Lexer->addEntryPattern($pattern, $mode, 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent()); } } public function postConnect() { foreach (self::getElements() as $element) { $this->Lexer->addExitPattern('', 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent()); } } /** * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text * @param Doku_Handler $handler The Doku_Handler object * @return array Return an array with all data you want to use in render */ public function handle($match, $state, $pos, Doku_Handler $handler) { // A metadata to tell if the page has a math expression or not // Use in the action plugin to add or not the library global $ID; p_set_metadata($ID,array(syntax_plugin_webcomponent_math::MATH_EXPRESSION =>false)); // The element is also needed by mathjax // pass the whole thing return array( 0 => $match ); } /** * Handles the actual output creation. * * @param $mode string output format being rendered * @param $renderer Doku_Renderer the current renderer object * @param $data array data created by handler() * @return boolean rendered correctly? */ public function render($mode, Doku_Renderer $renderer, $data) { $content = $data[0]; switch ($mode) { case 'xhtml': /** @var Doku_Renderer_xhtml $renderer */ $renderer->doc .= $renderer->_xmlEntities($content); break; case 'odt': /** @var Doku_Renderer_xhtml $renderer */ $renderer->doc .= $renderer->_xmlEntities($content); break; case 'latexport': // Pass math expressions to latexport renderer $renderer->mathjax_content($content); break; case 'metadata': // Adding a meta to say that there is a math expression global $ID; /** @var Doku_Renderer_metadata $renderer */ $renderer->meta[self::MATH_EXPRESSION]=true; $renderer->persistent[self::MATH_EXPRESSION]=true; // TODO: What if the page is changed and that there is no math syntax anymore // Add a syntax to suppress the expression break; default: $renderer->doc .= $renderer->$data; break; } return true; } static public function getElements() { return webcomponent::getTags(get_called_class()); } public static function getComponentName() { return webcomponent::getTagName(get_called_class()); } }