/** * User handler for code block * @return Texy\HtmlElement */ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content, $lang, Texy\Modifier $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $lang = strtoupper($lang); if ($lang == 'JAVASCRIPT') { $lang = 'JS'; } $fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT); if (!$fshl->isLanguage($lang)) { return $invocation->proceed(); } $texy = $invocation->getTexy(); $content = Texy\Helpers::outdent($content); $content = $fshl->highlightString($lang, $content); $content = $texy->protect($content, $texy::CONTENT_BLOCK); $elPre = new Texy\HtmlElement('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = strtolower($lang); $elCode = $elPre->create('code', $content); return $elPre; }
/** * Pattern handler for inline syntaxes * * @param Texy\LineParser * @param array reg-exp matches * @param string pattern name (myInlineSyntax1 or myInlineSyntax2) * @return Texy\HtmlElement|string */ function userInlineHandler(Texy\LineParser $parser, array $matches, $name) { list(, $mContent, $mMod) = $matches; $texy = $parser->getTexy(); // create element $tag = $name === 'myInlineSyntax1' ? 'b' : 'i'; $el = new Texy\HtmlElement($tag); // apply modifier $mod = new Texy\Modifier($mMod); $mod->decorate($texy, $el); $el->attrs['class'] = 'myclass'; $el->setText($mContent); // parse inner content of this element $parser->again = TRUE; return $el; }