104fd306cSNickeau<?php 204fd306cSNickeau 304fd306cSNickeaunamespace ComboStrap; 404fd306cSNickeau 504fd306cSNickeau 604fd306cSNickeauuse ComboStrap\Meta\Field\PageH1; 704fd306cSNickeauuse ComboStrap\Tag\TableTag; 804fd306cSNickeauuse ComboStrap\TagAttribute\StyleAttribute; 904fd306cSNickeauuse dokuwiki\Extension\SyntaxPlugin; 1004fd306cSNickeauuse syntax_plugin_combo_analytics; 1104fd306cSNickeauuse syntax_plugin_combo_header; 1204fd306cSNickeauuse syntax_plugin_combo_headingatx; 1304fd306cSNickeauuse syntax_plugin_combo_headingwiki; 1404fd306cSNickeauuse syntax_plugin_combo_media; 1504fd306cSNickeau 1604fd306cSNickeau/** 1704fd306cSNickeau * The outline is creating a XML like document 1804fd306cSNickeau * with section 1904fd306cSNickeau * 2004fd306cSNickeau * It's also the post-processing of the instructions 2104fd306cSNickeau */ 2204fd306cSNickeauclass Outline 2304fd306cSNickeau{ 2404fd306cSNickeau 2504fd306cSNickeau 2604fd306cSNickeau const CANONICAL = "outline"; 2704fd306cSNickeau private const OUTLINE_HEADING_PREFIX = "outline-heading"; 2804fd306cSNickeau const CONTEXT = self::CANONICAL; 2904fd306cSNickeau public const OUTLINE_HEADING_NUMBERING = "outline-heading-numbering"; 3004fd306cSNickeau public const TOC_NUMBERING = "toc-numbering"; 3104fd306cSNickeau /** 3204fd306cSNickeau * As seen on 3304fd306cSNickeau * https://drafts.csswg.org/css-counter-styles-3/#predefined-counters 3404fd306cSNickeau */ 3504fd306cSNickeau public const CONF_COUNTER_STYLES_CHOICES = [ 3604fd306cSNickeau 'arabic-indic', 3704fd306cSNickeau 'bengali', 3804fd306cSNickeau 'cambodian/khmer', 3904fd306cSNickeau 'cjk-decimal', 4004fd306cSNickeau 'decimal', 4104fd306cSNickeau 'decimal-leading-zero', 4204fd306cSNickeau 'devanagari', 4304fd306cSNickeau 'georgian', 4404fd306cSNickeau 'gujarati', 4504fd306cSNickeau 'gurmukhi', 4604fd306cSNickeau 'hebrew', 4704fd306cSNickeau 'hiragana', 4804fd306cSNickeau 'hiragana-iroha', 4904fd306cSNickeau 'kannada', 5004fd306cSNickeau 'katakana', 5104fd306cSNickeau 'katakana-iroha', 5204fd306cSNickeau 'lao', 5304fd306cSNickeau 'lower-alpha', 5404fd306cSNickeau 'lower-armenian', 5504fd306cSNickeau 'lower-greek', 5604fd306cSNickeau 'lower-roman', 5704fd306cSNickeau 'malayalam', 5804fd306cSNickeau 'mongolian', 5904fd306cSNickeau 'myanmar', 6004fd306cSNickeau 'oriya', 6104fd306cSNickeau 'persian', 6204fd306cSNickeau 'tamil', 6304fd306cSNickeau 'telugu', 6404fd306cSNickeau 'thai', 6504fd306cSNickeau 'tibetan', 6604fd306cSNickeau 'upper-alpha', 6704fd306cSNickeau 'upper-armenian', 6804fd306cSNickeau 'upper-roman' 6904fd306cSNickeau ]; 7004fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL4 = "outlineNumberingCounterStyleLevel4"; 7104fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL3 = "outlineNumberingCounterStyleLevel3"; 7204fd306cSNickeau public const CONF_OUTLINE_NUMBERING_SUFFIX = "outlineNumberingSuffix"; 7304fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL2 = "outlineNumberingCounterStyleLevel2"; 7404fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_SEPARATOR = "outlineNumberingCounterSeparator"; 7504fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL6 = "outlineNumberingCounterStyleLevel6"; 7604fd306cSNickeau public const CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL5 = "outlineNumberingCounterStyleLevel5"; 7704fd306cSNickeau public const CONF_OUTLINE_NUMBERING_PREFIX = "outlineNumberingPrefix"; 7804fd306cSNickeau public const CONF_OUTLINE_NUMBERING_ENABLE = "outlineNumberingEnable"; 7904fd306cSNickeau /** 8004fd306cSNickeau * To add hash tag to heading 8104fd306cSNickeau */ 8204fd306cSNickeau public const OUTLINE_ANCHOR = "outline-anchor"; 8304fd306cSNickeau const CONF_OUTLINE_NUMBERING_ENABLE_DEFAULT = 1; 8404fd306cSNickeau private OutlineSection $rootSection; 8504fd306cSNickeau 8604fd306cSNickeau private OutlineSection $actualSection; // the actual section that is created 8704fd306cSNickeau private Call $actualHeadingCall; // the heading that is parsed 8804fd306cSNickeau private int $actualHeadingParsingState = DOKU_LEXER_EXIT; // the state of the heading parsed (enter, closed), enter if we have entered an heading, exit if not; 8904fd306cSNickeau private ?MarkupPath $markupPath = null; 9004fd306cSNickeau private bool $isFragment; 9104fd306cSNickeau private bool $metaHeaderCapture; 9204fd306cSNickeau 9304fd306cSNickeau /** 9404fd306cSNickeau * @param CallStack $callStack 9504fd306cSNickeau * @param MarkupPath|null $markup - needed to store the parsed toc, h1, ... (null if the markup is dynamic) 9604fd306cSNickeau * @param bool $isFragment - needed to control the structure of the outline (if this is a preview, the first heading may be not h1) 9704fd306cSNickeau * @return void 9804fd306cSNickeau */ 9904fd306cSNickeau public function __construct(CallStack $callStack, MarkupPath $markup = null, bool $isFragment = false) 10004fd306cSNickeau { 10104fd306cSNickeau if ($markup !== null) { 10204fd306cSNickeau $this->markupPath = $markup; 10304fd306cSNickeau } 10404fd306cSNickeau $this->isFragment = $isFragment; 10504fd306cSNickeau $this->buildOutline($callStack); 10604fd306cSNickeau $this->storeH1(); 10704fd306cSNickeau $this->storeTocForMarkupIfAny(); 10804fd306cSNickeau } 10904fd306cSNickeau 11004fd306cSNickeau /** 11104fd306cSNickeau * @param CallStack $callStack 11204fd306cSNickeau * @param MarkupPath|null $markupPath - needed to store the parsed toc, h1, ... (null if the markup is dynamic) 11304fd306cSNickeau * @param bool $isFragment - needed to control the structure of the outline (if this is a preview, the first heading may be not h1) 11404fd306cSNickeau * @return Outline 11504fd306cSNickeau */ 11604fd306cSNickeau public static function createFromCallStack(CallStack $callStack, MarkupPath $markupPath = null, bool $isFragment = false): Outline 11704fd306cSNickeau { 11804fd306cSNickeau return new Outline($callStack, $markupPath, $isFragment); 11904fd306cSNickeau } 12004fd306cSNickeau 12104fd306cSNickeau private function buildOutline(CallStack $callStack) 12204fd306cSNickeau { 12304fd306cSNickeau 12404fd306cSNickeau /** 12504fd306cSNickeau * {@link syntax_plugin_combo_analytics tag analytics} 12604fd306cSNickeau * By default, in a test environment 12704fd306cSNickeau * this is set to 0 12804fd306cSNickeau * to speed test and to not pollute 12904fd306cSNickeau */ 13004fd306cSNickeau $analtyicsEnabled = SiteConfig::getConfValue(syntax_plugin_combo_analytics::CONF_SYNTAX_ANALYTICS_ENABLE, true); 13104fd306cSNickeau $analyticsTagUsed = []; 13204fd306cSNickeau 13304fd306cSNickeau /** 13404fd306cSNickeau * Processing variable about the context 13504fd306cSNickeau */ 13604fd306cSNickeau $this->rootSection = OutlineSection::createOutlineRoot() 13704fd306cSNickeau ->setStartPosition(0); 13804fd306cSNickeau $this->actualSection = $this->rootSection; 13904fd306cSNickeau $actualLastPosition = 0; 14004fd306cSNickeau $callStack->moveToStart(); 14104fd306cSNickeau while ($actualCall = $callStack->next()) { 14204fd306cSNickeau 14304fd306cSNickeau 14404fd306cSNickeau $state = $actualCall->getState(); 14504fd306cSNickeau 14604fd306cSNickeau /** 14704fd306cSNickeau * Block Post Processing 14804fd306cSNickeau * to not get any unwanted p 14904fd306cSNickeau * to counter {@link Block::process()} 15004fd306cSNickeau * setting dynamically the {@link SyntaxPlugin::getPType()} 15104fd306cSNickeau * 15204fd306cSNickeau * Unfortunately, it can't work because this is called after 15304fd306cSNickeau * {@link Block::process()} 15404fd306cSNickeau */ 15504fd306cSNickeau if ($analtyicsEnabled) { 15604fd306cSNickeau 15704fd306cSNickeau if (in_array($state, CallStack::TAG_STATE)) { 158aea52b49Sgerardnico $tagName = $actualCall->getTagName(); 15904fd306cSNickeau // The dokuwiki component name have open in their name 16004fd306cSNickeau $tagName = str_replace("_open", "", $tagName); 161aea52b49Sgerardnico $actual = $analyticsTagUsed[$tagName] ?? 0; 162aea52b49Sgerardnico $analyticsTagUsed[$tagName] = $actual + 1; 16304fd306cSNickeau } 16404fd306cSNickeau 16504fd306cSNickeau } 16604fd306cSNickeau 16704fd306cSNickeau /** 16804fd306cSNickeau * We don't take the outline and document call if any 16904fd306cSNickeau * This is the case when we build from an actual stored instructions 17004fd306cSNickeau * (to bundle multiple page for instance) 17104fd306cSNickeau */ 17204fd306cSNickeau $tagName = $actualCall->getTagName(); 17304fd306cSNickeau switch ($tagName) { 17404fd306cSNickeau case "document_start": 17504fd306cSNickeau case "document_end": 17604fd306cSNickeau case SectionTag::TAG: 17704fd306cSNickeau continue 2; 17804fd306cSNickeau case syntax_plugin_combo_header::TAG: 17904fd306cSNickeau if ($actualCall->isPluginCall() && $actualCall->getContext() === self::CONTEXT) { 18004fd306cSNickeau continue 2; 18104fd306cSNickeau } 18204fd306cSNickeau } 18304fd306cSNickeau 18404fd306cSNickeau /** 18504fd306cSNickeau * Wrap the table 18604fd306cSNickeau */ 18704fd306cSNickeau $componentName = $actualCall->getComponentName(); 18804fd306cSNickeau if ($componentName === "table_open") { 18904fd306cSNickeau $position = $actualCall->getFirstMatchedCharacterPosition(); 19004fd306cSNickeau $originalInstructionCall = &$actualCall->getInstructionCall(); 19104fd306cSNickeau $originalInstructionCall = Call::createComboCall( 19204fd306cSNickeau TableTag::TAG, 19304fd306cSNickeau DOKU_LEXER_ENTER, 19404fd306cSNickeau [PluginUtility::POSITION => $position], 19504fd306cSNickeau null, 19604fd306cSNickeau null, 19704fd306cSNickeau null, 19804fd306cSNickeau $position, 19904fd306cSNickeau \syntax_plugin_combo_xmlblocktag::TAG 20004fd306cSNickeau )->toCallArray(); 20104fd306cSNickeau } 20204fd306cSNickeau 20304fd306cSNickeau /** 20404fd306cSNickeau * Enter new section ? 20504fd306cSNickeau */ 20604fd306cSNickeau $shouldWeCreateASection = false; 20704fd306cSNickeau switch ($tagName) { 20804fd306cSNickeau case syntax_plugin_combo_headingatx::TAG: 20904fd306cSNickeau $actualCall->setState(DOKU_LEXER_ENTER); 21004fd306cSNickeau if ($actualCall->getContext() === HeadingTag::TYPE_OUTLINE) { 21104fd306cSNickeau $shouldWeCreateASection = true; 21204fd306cSNickeau } 21304fd306cSNickeau $this->enterHeading($actualCall); 21404fd306cSNickeau break; 21504fd306cSNickeau case HeadingTag::HEADING_TAG: 21604fd306cSNickeau case syntax_plugin_combo_headingwiki::TAG: 21704fd306cSNickeau if ($state == DOKU_LEXER_ENTER 21804fd306cSNickeau && $actualCall->getContext() === HeadingTag::TYPE_OUTLINE) { 21904fd306cSNickeau $shouldWeCreateASection = true; 22004fd306cSNickeau $this->enterHeading($actualCall); 22104fd306cSNickeau } 22204fd306cSNickeau break; 22304fd306cSNickeau case "header": 22404fd306cSNickeau // Should happen only on outline section 22504fd306cSNickeau // we take over inside a component 22604fd306cSNickeau if (!$actualCall->isPluginCall()) { 22704fd306cSNickeau /** 22804fd306cSNickeau * ie not {@link syntax_plugin_combo_header} 22904fd306cSNickeau * but the dokuwiki header (ie heading) 23004fd306cSNickeau */ 23104fd306cSNickeau $shouldWeCreateASection = true; 23204fd306cSNickeau $this->enterHeading($actualCall); 23304fd306cSNickeau } 23404fd306cSNickeau break; 23504fd306cSNickeau } 23604fd306cSNickeau if ($shouldWeCreateASection) { 23704fd306cSNickeau if ($this->actualSection->hasParent()) { 23804fd306cSNickeau // -1 because the actual position is the start of the next section 23904fd306cSNickeau $this->actualSection->setEndPosition($actualCall->getFirstMatchedCharacterPosition() - 1); 24004fd306cSNickeau } 24104fd306cSNickeau $actualSectionLevel = $this->actualSection->getLevel(); 24204fd306cSNickeau 24304fd306cSNickeau if ($actualCall->isPluginCall()) { 24404fd306cSNickeau try { 24504fd306cSNickeau $newSectionLevel = DataType::toInteger($actualCall->getAttribute(HeadingTag::LEVEL)); 24604fd306cSNickeau } catch (ExceptionBadArgument $e) { 24704fd306cSNickeau LogUtility::internalError("The level was not present on the heading call", self::CANONICAL); 24804fd306cSNickeau $newSectionLevel = $actualSectionLevel; 24904fd306cSNickeau } 25004fd306cSNickeau } else { 25104fd306cSNickeau $headerTagName = $tagName; 25204fd306cSNickeau if ($headerTagName !== "header") { 25304fd306cSNickeau throw new ExceptionRuntimeInternal("This is not a dokuwiki header call", self::CANONICAL); 25404fd306cSNickeau } 25504fd306cSNickeau $newSectionLevel = $actualCall->getInstructionCall()[1][1]; 25604fd306cSNickeau } 25704fd306cSNickeau 25804fd306cSNickeau 25904fd306cSNickeau $newOutlineSection = OutlineSection::createFromEnterHeadingCall($actualCall); 26004fd306cSNickeau $sectionDiff = $newSectionLevel - $actualSectionLevel; 26104fd306cSNickeau if ($sectionDiff > 0) { 26204fd306cSNickeau 26304fd306cSNickeau /** 26404fd306cSNickeau * A child of the actual section 26504fd306cSNickeau * We append it first before the message check to 26604fd306cSNickeau * build the {@link TreeNode::getTreeIdentifier()} 26704fd306cSNickeau */ 26804fd306cSNickeau try { 26904fd306cSNickeau $this->actualSection->appendChild($newOutlineSection); 27004fd306cSNickeau } catch (ExceptionBadState $e) { 27104fd306cSNickeau throw new ExceptionRuntimeInternal("The node is not added multiple time, this error should not fired. Error:{$e->getMessage()}", self::CANONICAL, 1, $e); 27204fd306cSNickeau } 27304fd306cSNickeau 27404fd306cSNickeau if ($sectionDiff > 1 & !($actualSectionLevel === 0 && $newSectionLevel === 2)) { 27504fd306cSNickeau $expectedLevel = $actualSectionLevel + 1; 27604fd306cSNickeau if ($actualSectionLevel === 0) { 27704fd306cSNickeau /** 27804fd306cSNickeau * In a fragment run (preview), 27904fd306cSNickeau * the first heading may not be the first one 28004fd306cSNickeau */ 28104fd306cSNickeau if (!$this->isFragment) { 28204fd306cSNickeau $message = "The first section heading should have the level 1 or 2 (not $newSectionLevel)."; 28304fd306cSNickeau } 28404fd306cSNickeau } else { 28504fd306cSNickeau $message = "The child section heading ($actualSectionLevel) has the level ($newSectionLevel) but is parent ({$this->actualSection->getLabel()}) has the level ($actualSectionLevel). The expected level is ($expectedLevel)."; 28604fd306cSNickeau } 28704fd306cSNickeau if (isset($message)) { 28804fd306cSNickeau LogUtility::warning($message, self::CANONICAL); 28904fd306cSNickeau } 29004fd306cSNickeau $actualCall->setAttribute(HeadingTag::LEVEL, $newSectionLevel); 29104fd306cSNickeau } 29204fd306cSNickeau 29304fd306cSNickeau } else { 29404fd306cSNickeau 29504fd306cSNickeau /** 29604fd306cSNickeau * A child of the parent section, A sibling of the actual session 29704fd306cSNickeau */ 29804fd306cSNickeau try { 29904fd306cSNickeau $parent = $this->actualSection->getParent(); 30004fd306cSNickeau for ($i = 0; $i < abs($sectionDiff); $i++) { 30104fd306cSNickeau $parent = $parent->getParent(); 30204fd306cSNickeau } 30304fd306cSNickeau try { 30404fd306cSNickeau $parent->appendChild($newOutlineSection); 30504fd306cSNickeau } catch (ExceptionBadState $e) { 30604fd306cSNickeau throw new ExceptionRuntimeInternal("The node is not added multiple time, this error should not fired. Error:{$e->getMessage()}", self::CANONICAL, 1, $e); 30704fd306cSNickeau } 30804fd306cSNickeau } catch (ExceptionNotFound $e) { 30904fd306cSNickeau /** 31004fd306cSNickeau * no parent 31104fd306cSNickeau * May happen in preview (ie fragment) 31204fd306cSNickeau */ 31304fd306cSNickeau if (!$this->isFragment) { 31404fd306cSNickeau LogUtility::internalError("Due to the level logic, the actual section should have a parent"); 31504fd306cSNickeau } 31604fd306cSNickeau try { 31704fd306cSNickeau $this->actualSection->appendChild($newOutlineSection); 31804fd306cSNickeau } catch (ExceptionBadState $e) { 31904fd306cSNickeau throw new ExceptionRuntimeInternal("The node is not added multiple time, this error should not fired. Error:{$e->getMessage()}", self::CANONICAL, 1, $e); 32004fd306cSNickeau } 32104fd306cSNickeau } 32204fd306cSNickeau 32304fd306cSNickeau } 32404fd306cSNickeau 32504fd306cSNickeau $this->actualSection = $newOutlineSection; 32604fd306cSNickeau continue; 32704fd306cSNickeau } 32804fd306cSNickeau 32904fd306cSNickeau /** 33004fd306cSNickeau * Track the number of lines 33104fd306cSNickeau * to inject ads 33204fd306cSNickeau */ 33304fd306cSNickeau switch ($tagName) { 33404fd306cSNickeau case "linebreak": 33504fd306cSNickeau case "tablerow": 33604fd306cSNickeau // linebreak is an inline component 33704fd306cSNickeau $this->actualSection->incrementLineNumber(); 33804fd306cSNickeau break; 33904fd306cSNickeau default: 34004fd306cSNickeau $display = $actualCall->getDisplay(); 34104fd306cSNickeau if ($display === Call::BlOCK_DISPLAY) { 34204fd306cSNickeau $this->actualSection->incrementLineNumber(); 34304fd306cSNickeau } 34404fd306cSNickeau break; 34504fd306cSNickeau } 34604fd306cSNickeau 34704fd306cSNickeau /** 34804fd306cSNickeau * Track the position in the file 34904fd306cSNickeau */ 35004fd306cSNickeau $currentLastPosition = $actualCall->getLastMatchedCharacterPosition(); 35104fd306cSNickeau if ($currentLastPosition > $actualLastPosition) { 35204fd306cSNickeau // the position in the stack is not always good 35304fd306cSNickeau $actualLastPosition = $currentLastPosition; 35404fd306cSNickeau } 35504fd306cSNickeau 35604fd306cSNickeau 35704fd306cSNickeau switch ($actualCall->getComponentName()) { 35804fd306cSNickeau case \action_plugin_combo_instructionspostprocessing::EDIT_SECTION_OPEN: 35904fd306cSNickeau case \action_plugin_combo_instructionspostprocessing::EDIT_SECTION_CLOSE: 36004fd306cSNickeau // we don't store them 36104fd306cSNickeau continue 2; 36204fd306cSNickeau } 36304fd306cSNickeau 36404fd306cSNickeau /** 36504fd306cSNickeau * Close/Process the heading description 36604fd306cSNickeau */ 36704fd306cSNickeau if ($this->actualHeadingParsingState === DOKU_LEXER_ENTER) { 36804fd306cSNickeau switch ($tagName) { 36904fd306cSNickeau 37004fd306cSNickeau case HeadingTag::HEADING_TAG: 37104fd306cSNickeau case syntax_plugin_combo_headingwiki::TAG: 37204fd306cSNickeau if ($state == DOKU_LEXER_EXIT) { 37304fd306cSNickeau $this->addCallToSection($actualCall); 37404fd306cSNickeau $this->exitHeading(); 37504fd306cSNickeau continue 2; 37604fd306cSNickeau } 37704fd306cSNickeau break; 37804fd306cSNickeau 37904fd306cSNickeau case "internalmedia": 38004fd306cSNickeau // no link for media in heading 38104fd306cSNickeau $actualCall->getInstructionCall()[1][6] = MediaMarkup::LINKING_NOLINK_VALUE; 38204fd306cSNickeau break; 38304fd306cSNickeau case syntax_plugin_combo_media::TAG: 38404fd306cSNickeau // no link for media in heading 38504fd306cSNickeau $actualCall->addAttribute(MediaMarkup::LINKING_KEY, MediaMarkup::LINKING_NOLINK_VALUE); 38604fd306cSNickeau break; 38704fd306cSNickeau 38804fd306cSNickeau case "header": 38904fd306cSNickeau if (SiteConfig::getConfValue(syntax_plugin_combo_headingwiki::CONF_WIKI_HEADING_ENABLE, syntax_plugin_combo_headingwiki::CONF_DEFAULT_WIKI_ENABLE_VALUE) == 1) { 39004fd306cSNickeau LogUtility::msg("The combo heading wiki is enabled, we should not see `header` calls in the call stack"); 39104fd306cSNickeau } 39204fd306cSNickeau break; 39304fd306cSNickeau 39404fd306cSNickeau case "p": 39504fd306cSNickeau 39604fd306cSNickeau if ($this->actualHeadingCall->getTagName() === syntax_plugin_combo_headingatx::TAG) { 39704fd306cSNickeau // A new p is the end of an atx call 39804fd306cSNickeau switch ($actualCall->getComponentName()) { 39904fd306cSNickeau case "p_open": 40004fd306cSNickeau // We don't take the p tag inside atx heading 40104fd306cSNickeau // therefore we continue 40204fd306cSNickeau continue 3; 40304fd306cSNickeau case "p_close": 40404fd306cSNickeau $endAtxCall = Call::createComboCall( 40504fd306cSNickeau syntax_plugin_combo_headingatx::TAG, 40604fd306cSNickeau DOKU_LEXER_EXIT, 40704fd306cSNickeau $this->actualHeadingCall->getAttributes(), 40804fd306cSNickeau $this->actualHeadingCall->getContext(), 40904fd306cSNickeau ); 41004fd306cSNickeau $this->addCallToSection($endAtxCall); 41104fd306cSNickeau $this->exitHeading(); 41204fd306cSNickeau // We don't take the p tag inside atx heading 41304fd306cSNickeau // therefore we continue 41404fd306cSNickeau continue 3; 41504fd306cSNickeau } 41604fd306cSNickeau } 41704fd306cSNickeau break; 41804fd306cSNickeau 41904fd306cSNickeau } 42004fd306cSNickeau } 42104fd306cSNickeau $this->addCallToSection($actualCall); 42204fd306cSNickeau } 42304fd306cSNickeau 42404fd306cSNickeau // empty text 42504fd306cSNickeau if (sizeof($analyticsTagUsed) > 0) { 42604fd306cSNickeau $pluginAnalyticsCall = Call::createComboCall( 42704fd306cSNickeau syntax_plugin_combo_analytics::TAG, 42804fd306cSNickeau DOKU_LEXER_SPECIAL, 42904fd306cSNickeau $analyticsTagUsed 43004fd306cSNickeau ); 43104fd306cSNickeau $this->addCallToSection($pluginAnalyticsCall); 43204fd306cSNickeau } 43304fd306cSNickeau 43404fd306cSNickeau // Add label the heading text to the metadata 43504fd306cSNickeau $this->saveOutlineToMetadata(); 43604fd306cSNickeau 43704fd306cSNickeau 43804fd306cSNickeau } 43904fd306cSNickeau 44004fd306cSNickeau public static function getOutlineHeadingClass(): string 44104fd306cSNickeau { 44204fd306cSNickeau return StyleAttribute::addComboStrapSuffix(self::OUTLINE_HEADING_PREFIX); 44304fd306cSNickeau } 44404fd306cSNickeau 44504fd306cSNickeau public function getRootOutlineSection(): OutlineSection 44604fd306cSNickeau { 44704fd306cSNickeau return $this->rootSection; 44804fd306cSNickeau 44904fd306cSNickeau } 45004fd306cSNickeau 45104fd306cSNickeau /** 45204fd306cSNickeau */ 45304fd306cSNickeau public static function merge(Outline $inner, Outline $outer) 45404fd306cSNickeau { 45504fd306cSNickeau /** 45604fd306cSNickeau * Get the inner section where the outer section will be added 45704fd306cSNickeau */ 45804fd306cSNickeau $innerRootOutlineSection = $inner->getRootOutlineSection(); 45904fd306cSNickeau $innerTopSections = $innerRootOutlineSection->getChildren(); 46004fd306cSNickeau if (count($innerTopSections) === 0) { 46104fd306cSNickeau $firstInnerSection = $innerRootOutlineSection; 46204fd306cSNickeau } else { 46304fd306cSNickeau $firstInnerSection = $innerTopSections[count($innerTopSections)]; 46404fd306cSNickeau } 46504fd306cSNickeau $firstInnerSectionLevel = $firstInnerSection->getLevel(); 46604fd306cSNickeau 46704fd306cSNickeau /** 46804fd306cSNickeau * Add the outer sections 46904fd306cSNickeau */ 47004fd306cSNickeau $outerRootOutlineSection = $outer->getRootOutlineSection(); 47104fd306cSNickeau foreach ($outerRootOutlineSection->getChildren() as $childOuterSection) { 47204fd306cSNickeau /** 47304fd306cSNickeau * One level less than where the section is included 47404fd306cSNickeau */ 47504fd306cSNickeau $childOuterSection->setLevel($firstInnerSectionLevel + 1); 47604fd306cSNickeau $childOuterSection->detachBeforeAppend(); 47704fd306cSNickeau try { 47804fd306cSNickeau $firstInnerSection->appendChild($childOuterSection); 47904fd306cSNickeau } catch (ExceptionBadState $e) { 48004fd306cSNickeau // We add the node only once. This error should not happen 48104fd306cSNickeau throw new ExceptionRuntimeInternal("Error while adding a section during the outline merge. Error: {$e->getMessage()}", self::CANONICAL, 1, $e); 48204fd306cSNickeau } 48304fd306cSNickeau } 48404fd306cSNickeau 48504fd306cSNickeau } 48604fd306cSNickeau 48704fd306cSNickeau public static function mergeRecurse(Outline $inner, Outline $outer) 48804fd306cSNickeau { 48904fd306cSNickeau $innerRootOutlineSection = $inner->getRootOutlineSection(); 49004fd306cSNickeau $outerRootOutlineSection = $outer->getRootOutlineSection(); 49104fd306cSNickeau 49204fd306cSNickeau } 49304fd306cSNickeau 49404fd306cSNickeau /** 49504fd306cSNickeau * Utility class to create a outline from a markup string 49604fd306cSNickeau * @param string $content 49704fd306cSNickeau * @return Outline 49804fd306cSNickeau */ 49904fd306cSNickeau public static function createFromMarkup(string $content, Path $contentPath, WikiPath $contextPath): Outline 50004fd306cSNickeau { 50104fd306cSNickeau $instructions = MarkupRenderer::createFromMarkup($content, $contentPath, $contextPath) 50204fd306cSNickeau ->setRequestedMimeToInstruction() 50304fd306cSNickeau ->getOutput(); 50404fd306cSNickeau $callStack = CallStack::createFromInstructions($instructions); 50504fd306cSNickeau return Outline::createFromCallStack($callStack); 50604fd306cSNickeau } 50704fd306cSNickeau 50804fd306cSNickeau /** 50904fd306cSNickeau * Get the heading numbering snippet 51004fd306cSNickeau * @param string $type heading or toc - for {@link Outline::TOC_NUMBERING} or {@link Outline::OUTLINE_HEADING_NUMBERING} 51104fd306cSNickeau * @return string - the css internal stylesheet 51204fd306cSNickeau * @throws ExceptionNotEnabled 51304fd306cSNickeau * @throws ExceptionBadSyntax 51404fd306cSNickeau * Page on DokuWiki 51504fd306cSNickeau * https://www.dokuwiki.org/tips:numbered_headings 51604fd306cSNickeau */ 51704fd306cSNickeau public static function getCssNumberingRulesFor(string $type): string 51804fd306cSNickeau { 51904fd306cSNickeau 52004fd306cSNickeau $enable = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_ENABLE, Outline::CONF_OUTLINE_NUMBERING_ENABLE_DEFAULT); 52104fd306cSNickeau if (!$enable) { 52204fd306cSNickeau throw new ExceptionNotEnabled(); 52304fd306cSNickeau } 52404fd306cSNickeau 52504fd306cSNickeau $level2CounterStyle = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL2, "decimal"); 52604fd306cSNickeau $level3CounterStyle = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL3, "decimal"); 52704fd306cSNickeau $level4CounterStyle = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL4, "decimal"); 52804fd306cSNickeau $level5CounterStyle = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL5, "decimal"); 52904fd306cSNickeau $level6CounterStyle = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_STYLE_LEVEL6, "decimal"); 53004fd306cSNickeau $counterSeparator = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_COUNTER_SEPARATOR, "."); 53104fd306cSNickeau $prefix = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_PREFIX, ""); 53204fd306cSNickeau $suffix = SiteConfig::getConfValue(self::CONF_OUTLINE_NUMBERING_SUFFIX, " - "); 53304fd306cSNickeau 53404fd306cSNickeau switch ($type) { 53504fd306cSNickeau 53604fd306cSNickeau case self::OUTLINE_HEADING_NUMBERING: 53704fd306cSNickeau global $ACT; 53804fd306cSNickeau /** 53904fd306cSNickeau * Because the HTML file structure is not really fixed 54004fd306cSNickeau * (we may have section HTML element with a bar, the sectioning heading 54104fd306cSNickeau * may be not enabled) 54204fd306cSNickeau * We can't select via html structure 54304fd306cSNickeau * the outline heading consistently 54404fd306cSNickeau * We do it then with the class value 54504fd306cSNickeau */ 54604fd306cSNickeau $outlineClass = Outline::getOutlineHeadingClass(); 547*ef115533Sgerardnico $reset = ""; 548*ef115533Sgerardnico if ($ACT === "preview") { 549*ef115533Sgerardnico $mainContainerSelector = ".pad"; 550*ef115533Sgerardnico $reset = <<<EOF 551*ef115533Sgerardnico$mainContainerSelector { counter-reset: h2; } 552*ef115533Sgerardnico$mainContainerSelector h2.$outlineClass { counter-increment: h2 1; counter-reset: h3 h4 h5 h6;} 553*ef115533Sgerardnico$mainContainerSelector h3.$outlineClass { counter-increment: h3 1; counter-reset: h4 h5 h6;} 554*ef115533Sgerardnico$mainContainerSelector h4.$outlineClass { counter-increment: h4 1; counter-reset: h5 h6;} 555*ef115533Sgerardnico$mainContainerSelector h5.$outlineClass { counter-increment: h5 1; counter-reset: h6;} 556*ef115533Sgerardnico$mainContainerSelector h6.$outlineClass { counter-increment: h6 1; } 557*ef115533SgerardnicoEOF; 558*ef115533Sgerardnico } else { 559*ef115533Sgerardnico $mainContainerSelector = "#" . TemplateSlot::MAIN_CONTENT_ID; 560*ef115533Sgerardnico $reset = <<<EOF 561*ef115533Sgerardnico$mainContainerSelector { counter-reset: h2; } 562*ef115533Sgerardnico$mainContainerSelector section.outline-section-cs section.outline-section-cs { counter-increment: h2; counter-reset: h3 h4 h5 h6;} 563*ef115533Sgerardnico$mainContainerSelector section.outline-section-cs section.outline-section-cs section.outline-section-cs { counter-increment: h3; counter-reset: h4 h5 h6;} 564*ef115533Sgerardnico$mainContainerSelector section.outline-section-cs section.outline-section-cs section.outline-section-cs section.outline-section-cs { counter-increment: h4; counter-reset: h5 h6;} 565*ef115533Sgerardnico$mainContainerSelector section.outline-section-cs section.outline-section-cs section.outline-section-cs section.outline-section-cs section.outline-section-cs { counter-increment: h5; counter-reset: h6;} 566*ef115533SgerardnicoEOF; 567*ef115533Sgerardnico 568*ef115533Sgerardnico } 56904fd306cSNickeau return <<<EOF 570*ef115533Sgerardnico$reset 571effabefcSgerardnico$mainContainerSelector h2.$outlineClass::before { content: "$prefix" counter(h2, $level2CounterStyle) "$suffix\A"; } 572effabefcSgerardnico$mainContainerSelector h3.$outlineClass::before { content: "$prefix" counter(h2, $level2CounterStyle) "$counterSeparator" counter(h3,$level3CounterStyle) "$suffix\A"; } 573effabefcSgerardnico$mainContainerSelector h4.$outlineClass::before { content: "$prefix" counter(h2, $level2CounterStyle) "$counterSeparator" counter(h3,$level3CounterStyle) "$counterSeparator" counter(h4,$level4CounterStyle) "$suffix\A"; } 574effabefcSgerardnico$mainContainerSelector h5.$outlineClass::before { content: "$prefix" counter(h2, $level2CounterStyle) "$counterSeparator" counter(h3,$level3CounterStyle) "$counterSeparator" counter(h4,$level4CounterStyle) "$counterSeparator" counter(h5,$level5CounterStyle) "$suffix\A"; } 575effabefcSgerardnico$mainContainerSelector h6.$outlineClass::before { content: "$prefix" counter(h2, $level2CounterStyle) "$counterSeparator" counter(h3,$level3CounterStyle) "$counterSeparator" counter(h4,$level4CounterStyle) "$counterSeparator" counter(h5,$level5CounterStyle) "$counterSeparator" counter(h6,$level6CounterStyle) "$suffix\A"; } 57604fd306cSNickeauEOF; 577*ef115533Sgerardnico 578*ef115533Sgerardnico 57904fd306cSNickeau case self::TOC_NUMBERING: 58004fd306cSNickeau /** 58104fd306cSNickeau * The level counter on the toc are based 58204fd306cSNickeau * on the https://www.dokuwiki.org/config:toptoclevel 58304fd306cSNickeau * configuration 58404fd306cSNickeau * if toptoclevel = 2, then level1 = h2 and not h1 58504fd306cSNickeau * @deprecated 58604fd306cSNickeau */ 58704fd306cSNickeau // global $conf; 58804fd306cSNickeau // $topTocLevel = $conf['toptoclevel']; 58904fd306cSNickeau 59004fd306cSNickeau $tocSelector = "." . Toc::getClass() . " ul"; 59104fd306cSNickeau return <<<EOF 59204fd306cSNickeau$tocSelector li { counter-increment: toc2; } 59304fd306cSNickeau$tocSelector li li { counter-increment: toc3; } 59404fd306cSNickeau$tocSelector li li li { counter-increment: toc4; } 59504fd306cSNickeau$tocSelector li li li li { counter-increment: toc5; } 59604fd306cSNickeau$tocSelector li li li li li { counter-increment: toc6; } 59704fd306cSNickeau$tocSelector li a::before { content: "$prefix" counter(toc2, $level2CounterStyle) "$suffix\A"; } 59804fd306cSNickeau$tocSelector li li a::before { content: "$prefix" counter(toc2, $level2CounterStyle) "$counterSeparator" counter(toc3,$level3CounterStyle) "$suffix\A"; } 59904fd306cSNickeau$tocSelector li li li a::before { content: "$prefix" counter(toc2, $level2CounterStyle) "$counterSeparator" counter(toc3,$level3CounterStyle) "$counterSeparator" counter(toc4,$level4CounterStyle) "$suffix\A"; } 60004fd306cSNickeau$tocSelector li li li li a::before { content: "$prefix" counter(toc2, $level2CounterStyle) "$counterSeparator" counter(toc3,$level3CounterStyle) "$counterSeparator" counter(toc4,$level4CounterStyle) "$counterSeparator" counter(toc5,$level5CounterStyle) "$suffix\A"; } 60104fd306cSNickeau$tocSelector li li li li li a::before { content: "$prefix" counter(toc2, $level2CounterStyle) "$counterSeparator" counter(toc3,$level3CounterStyle) "$counterSeparator" counter(toc4,$level4CounterStyle) "$counterSeparator" counter(toc5,$level5CounterStyle) "$counterSeparator" counter(toc6,$level6CounterStyle) "$suffix\A"; } 60204fd306cSNickeauEOF; 60304fd306cSNickeau 60404fd306cSNickeau default: 60504fd306cSNickeau throw new ExceptionBadSyntax("The type ($type) is unknown"); 60604fd306cSNickeau } 60704fd306cSNickeau 60804fd306cSNickeau 60904fd306cSNickeau } 61004fd306cSNickeau 61104fd306cSNickeau /** 61204fd306cSNickeau * @throws ExceptionNotFound 61304fd306cSNickeau */ 61404fd306cSNickeau public static function createFromMarkupPath(MarkupPath $markupPath): Outline 61504fd306cSNickeau { 61604fd306cSNickeau $path = $markupPath->getPathObject(); 61704fd306cSNickeau if (!($path instanceof WikiPath)) { 61804fd306cSNickeau throw new ExceptionRuntimeInternal("The path is not a wiki path"); 61904fd306cSNickeau } 62004fd306cSNickeau $markup = FileSystems::getContent($path); 62104fd306cSNickeau $instructions = MarkupRenderer::createFromMarkup($markup, $path, $path) 62204fd306cSNickeau ->setRequestedMimeToInstruction() 62304fd306cSNickeau ->getOutput(); 62404fd306cSNickeau $callStack = CallStack::createFromInstructions($instructions); 62504fd306cSNickeau return new Outline($callStack, $markupPath); 62604fd306cSNickeau } 62704fd306cSNickeau 62804fd306cSNickeau public function getInstructionCalls(): array 62904fd306cSNickeau { 63004fd306cSNickeau $totalInstructionCalls = []; 63104fd306cSNickeau $collectCalls = function (OutlineSection $outlineSection) use (&$totalInstructionCalls) { 63204fd306cSNickeau $instructionCalls = array_map(function (Call $element) { 63304fd306cSNickeau return $element->getInstructionCall(); 63404fd306cSNickeau }, $outlineSection->getCalls()); 63504fd306cSNickeau $totalInstructionCalls = array_merge($totalInstructionCalls, $instructionCalls); 63604fd306cSNickeau }; 63704fd306cSNickeau TreeVisit::visit($this->rootSection, $collectCalls); 63804fd306cSNickeau return $totalInstructionCalls; 63904fd306cSNickeau } 64004fd306cSNickeau 64104fd306cSNickeau public function toDokuWikiTemplateInstructionCalls(): array 64204fd306cSNickeau { 64304fd306cSNickeau $totalInstructionCalls = []; 64404fd306cSNickeau $sectionSequenceId = 0; 64504fd306cSNickeau $collectCalls = function (OutlineSection $outlineSection) use (&$totalInstructionCalls, &$sectionSequenceId) { 64604fd306cSNickeau 64704fd306cSNickeau $wikiSectionOpen = Call::createNativeCall( 64804fd306cSNickeau \action_plugin_combo_instructionspostprocessing::EDIT_SECTION_OPEN, 64904fd306cSNickeau array($outlineSection->getLevel()), 65004fd306cSNickeau $outlineSection->getStartPosition() 65104fd306cSNickeau ); 65204fd306cSNickeau $wikiSectionClose = Call::createNativeCall( 65304fd306cSNickeau \action_plugin_combo_instructionspostprocessing::EDIT_SECTION_CLOSE, 65404fd306cSNickeau array(), 65504fd306cSNickeau $outlineSection->getEndPosition() 65604fd306cSNickeau ); 65704fd306cSNickeau 65804fd306cSNickeau 65904fd306cSNickeau if ($outlineSection->hasParent()) { 66004fd306cSNickeau 66104fd306cSNickeau 66204fd306cSNickeau $sectionCalls = array_merge( 66304fd306cSNickeau $outlineSection->getHeadingCalls(), 66404fd306cSNickeau [$wikiSectionOpen], 66504fd306cSNickeau $outlineSection->getContentCalls(), 66604fd306cSNickeau [$wikiSectionClose], 66704fd306cSNickeau ); 66804fd306cSNickeau 66904fd306cSNickeau if ($this->isSectionEditingEnabled()) { 67004fd306cSNickeau 67104fd306cSNickeau /** 67204fd306cSNickeau * Adding sectionedit class to be conform 67304fd306cSNickeau * with the Dokuwiki {@link \Doku_Renderer_xhtml::header()} function 67404fd306cSNickeau */ 67504fd306cSNickeau $sectionSequenceId++; 67604fd306cSNickeau $headingCall = $outlineSection->getEnterHeadingCall(); 67704fd306cSNickeau if ($headingCall->isPluginCall()) { 67804fd306cSNickeau $level = DataType::toIntegerOrDefaultIfNull($headingCall->getAttribute(HeadingTag::LEVEL), 0); 67904fd306cSNickeau if ($level <= $this->getTocMaxLevel()) { 68004fd306cSNickeau $headingCall->addClassName("sectionedit$sectionSequenceId"); 68104fd306cSNickeau } 68204fd306cSNickeau } 68304fd306cSNickeau 68404fd306cSNickeau $editButton = EditButton::create($outlineSection->getLabel()) 68504fd306cSNickeau ->setStartPosition($outlineSection->getStartPosition()) 68604fd306cSNickeau ->setEndPosition($outlineSection->getEndPosition()) 68704fd306cSNickeau ->setOutlineHeadingId($outlineSection->getHeadingId()) 68804fd306cSNickeau ->setOutlineSectionId($sectionSequenceId) 68904fd306cSNickeau ->toComboCallDokuWikiForm(); 69004fd306cSNickeau $sectionCalls[] = $editButton; 69104fd306cSNickeau } 69204fd306cSNickeau 69304fd306cSNickeau } else { 69404fd306cSNickeau // dokuwiki seems to have no section for the content before the first heading 69504fd306cSNickeau $sectionCalls = $outlineSection->getContentCalls(); 69604fd306cSNickeau } 69704fd306cSNickeau 69804fd306cSNickeau $instructionCalls = array_map(function (Call $element) { 69904fd306cSNickeau return $element->getInstructionCall(); 70004fd306cSNickeau }, $sectionCalls); 70104fd306cSNickeau $totalInstructionCalls = array_merge($totalInstructionCalls, $instructionCalls); 70204fd306cSNickeau }; 70304fd306cSNickeau TreeVisit::visit($this->rootSection, $collectCalls); 70404fd306cSNickeau return $totalInstructionCalls; 70504fd306cSNickeau } 70604fd306cSNickeau 70704fd306cSNickeau private function addCallToSection(Call $actualCall) 70804fd306cSNickeau { 70904fd306cSNickeau if ($this->actualHeadingParsingState === DOKU_LEXER_ENTER && !$this->actualSection->hasContentCall()) { 71004fd306cSNickeau $this->actualSection->addHeaderCall($actualCall); 71104fd306cSNickeau } else { 71204fd306cSNickeau // an content heading (not outline) or another call 71304fd306cSNickeau $this->actualSection->addContentCall($actualCall); 71404fd306cSNickeau } 71504fd306cSNickeau } 71604fd306cSNickeau 71704fd306cSNickeau private function enterHeading(Call $actualCall) 71804fd306cSNickeau { 71904fd306cSNickeau $this->actualHeadingParsingState = DOKU_LEXER_ENTER; 72004fd306cSNickeau $this->actualHeadingCall = $actualCall; 72104fd306cSNickeau } 72204fd306cSNickeau 72304fd306cSNickeau private function exitHeading() 72404fd306cSNickeau { 72504fd306cSNickeau $this->actualHeadingParsingState = DOKU_LEXER_EXIT; 72604fd306cSNickeau } 72704fd306cSNickeau 72804fd306cSNickeau /** 72904fd306cSNickeau * @return array - Dokuwiki TOC array format 73004fd306cSNickeau */ 73104fd306cSNickeau public function toTocDokuwikiFormat(): array 73204fd306cSNickeau { 73304fd306cSNickeau 73404fd306cSNickeau $tableOfContent = []; 73504fd306cSNickeau $collectTableOfContent = function (OutlineSection $outlineSection) use (&$tableOfContent) { 73604fd306cSNickeau 73704fd306cSNickeau if (!$outlineSection->hasParent()) { 73804fd306cSNickeau // Root Section, no heading 73904fd306cSNickeau return; 74004fd306cSNickeau } 74104fd306cSNickeau $tableOfContent[] = [ 74204fd306cSNickeau 'link' => '#' . $outlineSection->getHeadingId(), 74304fd306cSNickeau 'title' => $outlineSection->getLabel(), 74404fd306cSNickeau 'type' => 'ul', 74504fd306cSNickeau 'level' => $outlineSection->getLevel() 74604fd306cSNickeau ]; 74704fd306cSNickeau 74804fd306cSNickeau }; 74904fd306cSNickeau TreeVisit::visit($this->rootSection, $collectTableOfContent); 75004fd306cSNickeau return $tableOfContent; 75104fd306cSNickeau 75204fd306cSNickeau } 75304fd306cSNickeau 75404fd306cSNickeau 75504fd306cSNickeau public 75604fd306cSNickeau function toHtmlSectionOutlineCalls(): array 75704fd306cSNickeau { 75804fd306cSNickeau return OutlineVisitor::create($this)->getCalls(); 75904fd306cSNickeau } 76004fd306cSNickeau 76104fd306cSNickeau 76204fd306cSNickeau /** 76304fd306cSNickeau * Fragment Rendering 76404fd306cSNickeau * * does not have any section/edit button 76504fd306cSNickeau * * no outline or edit button for dynamic rendering but closing of atx heading 76604fd306cSNickeau * 76704fd306cSNickeau * The outline processing ({@link Outline::buildOutline()} just close the atx heading 76804fd306cSNickeau * 76904fd306cSNickeau * @return array 77004fd306cSNickeau */ 77104fd306cSNickeau public 77204fd306cSNickeau function toFragmentInstructionCalls(): array 77304fd306cSNickeau { 77404fd306cSNickeau $totalInstructionCalls = []; 77504fd306cSNickeau $collectCalls = function (OutlineSection $outlineSection) use (&$totalInstructionCalls) { 77604fd306cSNickeau 77704fd306cSNickeau $sectionCalls = array_merge( 77804fd306cSNickeau $outlineSection->getHeadingCalls(), 77904fd306cSNickeau $outlineSection->getContentCalls() 78004fd306cSNickeau ); 78104fd306cSNickeau 78204fd306cSNickeau $instructionCalls = array_map(function (Call $element) { 78304fd306cSNickeau return $element->getInstructionCall(); 78404fd306cSNickeau }, $sectionCalls); 78504fd306cSNickeau $totalInstructionCalls = array_merge($totalInstructionCalls, $instructionCalls); 78604fd306cSNickeau }; 78704fd306cSNickeau TreeVisit::visit($this->rootSection, $collectCalls); 78804fd306cSNickeau return $totalInstructionCalls; 78904fd306cSNickeau 79004fd306cSNickeau } 79104fd306cSNickeau 79204fd306cSNickeau /** 79304fd306cSNickeau * Add the label (ie heading text to the cal attribute) 79404fd306cSNickeau * 79504fd306cSNickeau * @return void 79604fd306cSNickeau */ 79704fd306cSNickeau private 79804fd306cSNickeau function saveOutlineToMetadata() 79904fd306cSNickeau { 80004fd306cSNickeau try { 80104fd306cSNickeau $firstChild = $this->rootSection->getFirstChild(); 80204fd306cSNickeau } catch (ExceptionNotFound $e) { 80304fd306cSNickeau // no child 80404fd306cSNickeau return; 80504fd306cSNickeau } 80604fd306cSNickeau if ($firstChild->getLevel() === 1) { 80704fd306cSNickeau $headingCall = $firstChild->getEnterHeadingCall(); 80804fd306cSNickeau // not dokuwiki header ? 80904fd306cSNickeau if ($headingCall->isPluginCall()) { 81004fd306cSNickeau $headingCall->setAttribute(HeadingTag::HEADING_TEXT_ATTRIBUTE, $firstChild->getLabel()); 81104fd306cSNickeau } 81204fd306cSNickeau } 81304fd306cSNickeau 81404fd306cSNickeau } 81504fd306cSNickeau 81604fd306cSNickeau 81704fd306cSNickeau private 81804fd306cSNickeau function storeH1() 81904fd306cSNickeau { 82004fd306cSNickeau try { 82104fd306cSNickeau $outlineSection = $this->getRootOutlineSection()->getFirstChild(); 82204fd306cSNickeau } catch (ExceptionNotFound $e) { 82304fd306cSNickeau // 82404fd306cSNickeau return; 82504fd306cSNickeau } 82604fd306cSNickeau if ($this->markupPath != null && $outlineSection->getLevel() === 1) { 82704fd306cSNickeau $label = $outlineSection->getLabel(); 82804fd306cSNickeau $call = $outlineSection->getEnterHeadingCall(); 82904fd306cSNickeau if ($call->isPluginCall()) { 83004fd306cSNickeau // we support also the dokwuiki header call that does not need the label 83104fd306cSNickeau $call->addAttribute(HeadingTag::PARSED_LABEL, $label); 83204fd306cSNickeau } 83304fd306cSNickeau PageH1::createForPage($this->markupPath)->setDefaultValue($label); 83404fd306cSNickeau } 83504fd306cSNickeau } 83604fd306cSNickeau 83704fd306cSNickeau private 83804fd306cSNickeau function storeTocForMarkupIfAny() 83904fd306cSNickeau { 84004fd306cSNickeau 84104fd306cSNickeau $toc = $this->toTocDokuwikiFormat(); 84204fd306cSNickeau 84304fd306cSNickeau try { 84404fd306cSNickeau $fetcherMarkup = ExecutionContext::getActualOrCreateFromEnv()->getExecutingMarkupHandler(); 84504fd306cSNickeau $fetcherMarkup->toc = $toc; 84604fd306cSNickeau if ($fetcherMarkup->isDocument()) { 84704fd306cSNickeau /** 84804fd306cSNickeau * We still update the global TOC Dokuwiki variables 84904fd306cSNickeau */ 85004fd306cSNickeau global $TOC; 85104fd306cSNickeau $TOC = $toc; 85204fd306cSNickeau } 85304fd306cSNickeau } catch (ExceptionNotFound $e) { 85404fd306cSNickeau // outline is not runnned from a markup handler 85504fd306cSNickeau } 85604fd306cSNickeau 85704fd306cSNickeau if (!isset($this->markupPath)) { 85804fd306cSNickeau return; 85904fd306cSNickeau } 86004fd306cSNickeau 86104fd306cSNickeau try { 86204fd306cSNickeau Toc::createForPage($this->markupPath) 86304fd306cSNickeau ->setValue($toc) 86404fd306cSNickeau ->persist(); 86504fd306cSNickeau } catch (ExceptionBadArgument $e) { 86604fd306cSNickeau LogUtility::error("The Toc could not be persisted. Error:{$e->getMessage()}"); 86704fd306cSNickeau } 86804fd306cSNickeau } 86904fd306cSNickeau 87004fd306cSNickeau public 87104fd306cSNickeau function getMarkupPath(): ?MarkupPath 87204fd306cSNickeau { 87304fd306cSNickeau return $this->markupPath; 87404fd306cSNickeau } 87504fd306cSNickeau 87604fd306cSNickeau 87704fd306cSNickeau private 87804fd306cSNickeau function getTocMaxLevel(): int 87904fd306cSNickeau { 88004fd306cSNickeau return ExecutionContext::getActualOrCreateFromEnv() 88104fd306cSNickeau ->getConfig()->getTocMaxLevel(); 88204fd306cSNickeau } 88304fd306cSNickeau 88404fd306cSNickeau public function setMetaHeaderCapture(bool $metaHeaderCapture): Outline 88504fd306cSNickeau { 88604fd306cSNickeau $this->metaHeaderCapture = $metaHeaderCapture; 88704fd306cSNickeau return $this; 88804fd306cSNickeau } 88904fd306cSNickeau 89004fd306cSNickeau public function getMetaHeaderCapture(): bool 89104fd306cSNickeau { 89204fd306cSNickeau if (isset($this->metaHeaderCapture)) { 89304fd306cSNickeau return $this->metaHeaderCapture; 89404fd306cSNickeau } 89504fd306cSNickeau try { 89604fd306cSNickeau if ($this->markupPath !== null) { 89704fd306cSNickeau $contextPath = $this->markupPath->getPathObject()->toWikiPath(); 89804fd306cSNickeau $hasMainHeaderElement = TemplateForWebPage::create() 89904fd306cSNickeau ->setRequestedContextPath($contextPath) 90004fd306cSNickeau ->hasElement(TemplateSlot::MAIN_HEADER_ID); 90104fd306cSNickeau $isThemeSystemEnabled = ExecutionContext::getActualOrCreateFromEnv() 90204fd306cSNickeau ->getConfig() 90304fd306cSNickeau ->isThemeSystemEnabled(); 90404fd306cSNickeau if ($isThemeSystemEnabled && $hasMainHeaderElement) { 90504fd306cSNickeau return true; 90604fd306cSNickeau } 90704fd306cSNickeau } 90804fd306cSNickeau } catch (ExceptionCast $e) { 90904fd306cSNickeau // to Wiki Path should be good 91004fd306cSNickeau } 91104fd306cSNickeau return false; 91204fd306cSNickeau } 91304fd306cSNickeau 91404fd306cSNickeau public function isSectionEditingEnabled(): bool 91504fd306cSNickeau { 91604fd306cSNickeau 91704fd306cSNickeau return ExecutionContext::getActualOrCreateFromEnv() 91804fd306cSNickeau ->getConfig()->isSectionEditingEnabled(); 91904fd306cSNickeau 92004fd306cSNickeau } 92104fd306cSNickeau 92204fd306cSNickeau 92304fd306cSNickeau} 924