Skip to content
Snippets Groups Projects

ipa_haller_jan: QFQ-Wiki. refs #15634

Merged Jan Haller requested to merge ipa_haller_jan into develop
1 file
+ 24
12
Compare changes
  • Side-by-side
  • Inline
+ 24
12
@@ -75,6 +75,7 @@ function renderWiki($paramArray, $qfq) {
$content = $xpath->query('//*');
$counter = 1;
$firstElement = true;
// Iterate over each element
foreach ($content as $element) {
@@ -87,7 +88,7 @@ function renderWiki($paramArray, $qfq) {
// Looks for <h1> - <h6> elements or the first element
// Creates a <div> containing the edit link and an <a>-tag
// In printMode this will be skipped
if ((in_array($nodeName, $headingTags) || $counter === 1) && !$printMode) {
if ((in_array($nodeName, $headingTags) || $firstElement) && !$printMode) {
// If the first element is not <h1> - <h6>, then $sectionId = 0
$sectionId = (in_array($nodeName, $headingTags)) ? $counter : 0;
@@ -110,6 +111,7 @@ function renderWiki($paramArray, $qfq) {
// Reset values
$buttonText = '';
$action = WIKI_TOKEN_EDIT_SECTION;
$firstElement = false;
// Check for macro '{{toc}}'
if (trim($nodeValue) === WIKI_TOKEN_TABLE_OF_CONTENTS) {
@@ -171,17 +173,27 @@ function renderWiki($paramArray, $qfq) {
// Raw HTML
$wikiHtml = $dom->saveHTML();
// Search and replace opening collapse macro
// Opening <div>-tag gets inserted which acts as a parent for the collapsed content
// Search: <p>{{collapse(optional text)}}</p>
// Replace: <a><span></span>optional text</a></br><div>
$wikiHtml = preg_replace_callback('<<[a-zA-Z]+>{{collapse\((.*?)\)}}<[a-zA-Z/]+>>', 'doCollapse', $wikiHtml);
// Search and replace closing collapse macro
// Close previously opened <div>-tag
// Search: <p>{{collapse}}</p>
// Replace: </div>
$wikiHtml = preg_replace('<(<[a-zA-Z]+>{{collapse}}<[a-zA-Z/]+>)>', '</div>', $wikiHtml);
// HTML is different in print mode
if ($printMode) {
// Remove {{collapse()}} and {{collapse}}
// This keeps the content visible on the PDF
$wikiHtml = preg_replace('<<[a-zA-Z]+>{{collapse\((.*?)\)}}<[a-zA-Z/]+>>', '', $wikiHtml);
$wikiHtml = preg_replace('<(<[a-zA-Z]+>{{collapse}}<[a-zA-Z/]+>)>', '', $wikiHtml);
} else {
// Search and replace opening collapse macro
// Opening <div>-tag gets inserted which acts as a parent for the collapsed content
// Search: <p>{{collapse(optional text)}}</p>
// Replace: <a><span></span>optional text</a></br><div>
$wikiHtml = preg_replace_callback('<<[a-zA-Z]+>{{collapse\((.*?)\)}}<[a-zA-Z/]+>>', 'doCollapse', $wikiHtml);
// Search and replace closing collapse macro
// Close previously opened <div>-tag
// Search: <p>{{collapse}}</p>
// Replace: </div>
$wikiHtml = preg_replace('<(<[a-zA-Z]+>{{collapse}}<[a-zA-Z/]+>)>', '</div>', $wikiHtml);
}
// Output
echo $wikiHtml;
Loading