Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); } } public function postConnect() { foreach (self::TAGS as $tag) { $this->Lexer->addExitPattern('', PluginUtility::getModeFromTag($this->getPluginComponent())); } } /** * * The handle function goal is to parse the matched syntax through the pattern function * and to return the result for use in the renderer * This result is always cached until the page is modified. * @param string $match * @param int $state * @param int $pos * @param Doku_Handler $handler * @return array|bool * @see DokuWiki_Syntax_Plugin::handle() * */ function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: $default[BackgroundAttribute::BACKGROUND_COLOR] = 'light'; $default[self::BREAKPOINT_ATTRIBUTE] = "lg"; $default[self::THEME_ATTRIBUTE] = "light"; $default[self::POSITION] = "normal"; $default[ContainerTag::CONTAINER_ATTRIBUTE] = SiteConfig::getConfValue( ContainerTag::DEFAULT_LAYOUT_CONTAINER_CONF, ContainerTag::DEFAULT_LAYOUT_CONTAINER_DEFAULT_VALUE ); $tagAttributes = TagAttributes::createFromTagMatch($match, $default); return array( PluginUtility::STATE => $state, PluginUtility::ATTRIBUTES => $tagAttributes->toCallStackArray() ); case DOKU_LEXER_UNMATCHED: return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); case DOKU_LEXER_EXIT : return array( PluginUtility::STATE => $state ); } return array(); } /** * Render the output * @param string $format * @param Doku_Renderer $renderer * @param array $data - what the function handle() return'ed * @return boolean - rendered correctly? (however, returned value is not used at the moment) * @see DokuWiki_Syntax_Plugin::render() * * */ function render($format, Doku_Renderer $renderer, $data): bool { if ($format == 'xhtml') { /** @var Doku_Renderer_xhtml $renderer */ $state = $data[PluginUtility::STATE]; switch ($state) { case DOKU_LEXER_ENTER : $tagAttributes = TagAttributes::createFromCallStackArray($data[PluginUtility::ATTRIBUTES]); $tagAttributes->addClassName('navbar'); /** * Without the expand, the flex has a row direction * and not a column */ $breakpoint = $tagAttributes->getValueAndRemoveIfPresent(self::BREAKPOINT_ATTRIBUTE); $tagAttributes->addClassName("navbar-expand-$breakpoint"); // Grab the position $position = $tagAttributes->getValueAndRemove(self::POSITION); switch ($position) { case "top": $fixedTopClass = 'fixed-top'; /** * We don't set the class directly * because bootstrap uses `position: fixed` * Meaning that the content comes below * * We calculate the padding-top via the javascript but * it will then create a non-wanted layout-shift * * https://getbootstrap.com/docs/5.0/components/navbar/#placement * * We set the class and padding-top with the javascript */ $tagAttributes->addOutputAttributeValue("data-type", $fixedTopClass); $fixedTopSnippetId = self::TAG . "-" . $fixedTopClass; // See http://stackoverflow.com/questions/17181355/boostrap-using-fixed-navbar-and-anchor-tags-to-jump-to-sections PluginUtility::getSnippetManager()->attachJavascriptFromComponentId($fixedTopSnippetId); break; case "normal": // nothing break; default: LogUtility::error("The position value ($position) is not yet implemented", self::CANONICAL); break; } // Theming $theme = $tagAttributes->getValueAndRemove(self::THEME_ATTRIBUTE); $tagAttributes->addClassName("navbar-$theme"); // Container /** * Deprecated */ $align = $tagAttributes->getValueAndRemoveIfPresent(self::ALIGN_ATTRIBUTE); $container = null; if ($align !== null) { LogUtility::warning("The align attribute has been deprecated, you should delete it or use the container instead", self::CANONICAL); // Container if ($align === "center") { $container = "sm"; } else { $container = "fluid"; } } if ($container === null) { $container = $tagAttributes->getValueAndRemoveIfPresent(self::CONTAINER_ATTRIBUTE); } $containerClass = ContainerTag::getClassName($container); // The container should always be be inside to allow background $tagAttributes->addHtmlAfterEnterTag("
"); $renderer->doc .= $tagAttributes->toHtmlEnterTag("nav"); break; case DOKU_LEXER_UNMATCHED: $renderer->doc .= PluginUtility::renderUnmatched($data); break; case DOKU_LEXER_EXIT : $renderer->doc .= "
"; break; } return true; } return false; } }