/** * User handler for code block * * @param TexyHandlerInvocation handler invocation * @param string block type * @param string text to highlight * @param string language * @param TexyModifier modifier * @return TexyHtml */ function blockHandler($invocation, $blocktype, $content, $lang, $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::outdent($content); $content = $fshl->highlightString($lang, $content); $content = $texy->protect($content, Texy::CONTENT_BLOCK); $elPre = TexyHtml::el('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = strtolower($lang); $elCode = $elPre->create('code', $content); return $elPre; }
/** * User handler for code block. * * @param TexyHandlerInvocation handler invocation * @param string block type * @param string text to highlight * @param string language * @param TexyModifier modifier * @return TexyHtml */ public static function blockHandler($invocation, $blocktype, $content, $lang, $modifier) { if (preg_match('#^block/(php|neon|javascript|js|css|html|htmlcb|latte)$#', $blocktype)) { list(, $lang) = explode('/', $blocktype); } elseif ($blocktype !== 'block/code') { return $invocation->proceed(); } $lang = strtolower($lang); if ($lang === 'htmlcb' || $lang === 'latte') { $lang = 'html'; } elseif ($lang === 'javascript') { $lang = 'js'; } if ($lang === 'html') { $langClass = 'FSHL\\Lexer\\LatteHtml'; } elseif ($lang === 'js') { $langClass = 'FSHL\\Lexer\\LatteJavascript'; } else { $langClass = 'FSHL\\Lexer\\' . ucfirst($lang); } $texy = $invocation->getTexy(); $content = Texy::outdent($content); if (class_exists($langClass)) { $fshl = new FSHL\Highlighter(new FSHL\Output\Html(), FSHL\Highlighter::OPTION_TAB_INDENT); $content = $fshl->highlight($content, new $langClass()); } else { $content = htmlSpecialChars($content); } $content = $texy->protect($content, Texy::CONTENT_BLOCK); $elPre = TexyHtml::el('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = 'src-' . strtolower($lang); $elCode = $elPre->create('code', $content); return $elPre; }
/** * User handler for code block * * @param TexyHandlerInvocation handler invocation * @param string block type * @param string text to highlight * @param string language * @param TexyModifier modifier * @return TexyHtml */ function blockHandler($invocation, $blocktype, $content, $lang, $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $texy = $invocation->getTexy(); global $geshiPath; if ($lang == 'html') { $lang = 'html4strict'; } $content = Texy::outdent($content); $geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/'); // GeSHi could not find the language if ($geshi->error) { return $invocation->proceed(); } // do syntax-highlighting $geshi->set_encoding('UTF-8'); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_classes(); $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true); $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true); $geshi->set_code_style('color: #000020;', 'color: #000020;'); $geshi->set_link_styles(GESHI_LINK, 'color: #000060;'); $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); // save generated stylesheet $texy->styleSheet .= $geshi->get_stylesheet(); $content = $geshi->parse_code(); // check buggy GESHI, it sometimes produce not UTF-8 valid code :-(( $content = iconv('UTF-8', 'UTF-8//IGNORE', $content); // protect output is in HTML $content = $texy->protect($content, Texy::CONTENT_BLOCK); $el = TexyHtml::el(); $el->setText($content); return $el; }
private function finishPart($elPart) { $tx = $this->texy; foreach ($elPart->getChildren() as $elRow) { foreach ($elRow->getChildren() as $elCell) { if ($elCell->colSpan > 1) { $elCell->attrs['colspan'] = $elCell->colSpan; } if ($elCell->rowSpan > 1) { $elCell->attrs['rowspan'] = $elCell->rowSpan; } $text = rtrim($elCell->text); if (strpos($text, "\n") !== FALSE) { $elCell->parseBlock($tx, Texy::outdent($text)); } else { $elCell->parseLine($tx, ltrim($text)); } if ($elCell->getText() === '') { $elCell->setText("Β "); } } } }
static function texyBlockHandler($invocation, $blocktype, $content, $lang, $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $texy = $invocation->getTexy(); if ($lang == 'html') { $lang = 'html4strict'; } elseif ($lang == 'yaml') { $lang = 'python'; } $content = Texy::outdent($content); $geshi = new GeSHi($content, $lang); // GeSHi could not find the language if ($geshi->error) { return $invocation->proceed(); } // do syntax-highlighting $geshi->set_encoding('UTF-8'); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_classes(); $geshi->enable_keyword_links(false); $geshi->set_overall_style(''); $geshi->set_overall_class('code'); // save generated stylesheet $content = $geshi->parse_code(); // check buggy GESHI, it sometimes produce not UTF-8 valid code :-(( $content = iconv('UTF-8', 'UTF-8//IGNORE', $content); // protect output is in HTML $content = $texy->protect($content, Texy::CONTENT_BLOCK); $el = TexyHtml::el(); $el->setText($content); return $el; }
/** * Finish invocation. * * @param TexyHandlerInvocation handler invocation * @param string blocktype * @param string content * @param string additional parameter * @param TexyModifier * @return TexyHtml|string|FALSE */ public function solve($invocation, $blocktype, $s, $param, $mod) { $tx = $this->texy; $parser = $invocation->parser; if ($blocktype === 'block/texy') { $el = TexyHtml::el(); $el->parseBlock($tx, $s, $parser->isIndented()); return $el; } if (empty($tx->allowed[$blocktype])) { return FALSE; } if ($blocktype === 'block/texysource') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el(); if ($param === 'line') { $el->parseLine($tx, $s); } else { $el->parseBlock($tx, $s); } $s = $el->toHtml($tx); $blocktype = 'block/code'; $param = 'html'; // to be continue (as block/code) } if ($blocktype === 'block/code') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $s = Texy::escapeHtml($s); $s = $tx->protect($s, Texy::CONTENT_BLOCK); $el = TexyHtml::el('pre'); $mod->decorate($tx, $el); $el->attrs['class'][] = $param; // lang $el->create('code', $s); return $el; } if ($blocktype === 'block/default') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('pre'); $mod->decorate($tx, $el); $el->attrs['class'][] = $param; // lang $s = Texy::escapeHtml($s); $s = $tx->protect($s, Texy::CONTENT_BLOCK); $el->setText($s); return $el; } if ($blocktype === 'block/pre') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('pre'); $mod->decorate($tx, $el); $lineParser = new TexyLineParser($tx, $el); // special mode - parse only html tags $tmp = $lineParser->patterns; $lineParser->patterns = array(); if (isset($tmp['html/tag'])) { $lineParser->patterns['html/tag'] = $tmp['html/tag']; } if (isset($tmp['html/comment'])) { $lineParser->patterns['html/comment'] = $tmp['html/comment']; } unset($tmp); $lineParser->parse($s); $s = $el->getText(); $s = Texy::unescapeHtml($s); $s = Texy::escapeHtml($s); $s = $tx->unprotect($s); $s = $tx->protect($s, Texy::CONTENT_BLOCK); $el->setText($s); return $el; } if ($blocktype === 'block/html') { $s = trim($s, "\n"); if ($s === '') { return "\n"; } $el = TexyHtml::el(); $lineParser = new TexyLineParser($tx, $el); // special mode - parse only html tags $tmp = $lineParser->patterns; $lineParser->patterns = array(); if (isset($tmp['html/tag'])) { $lineParser->patterns['html/tag'] = $tmp['html/tag']; } if (isset($tmp['html/comment'])) { $lineParser->patterns['html/comment'] = $tmp['html/comment']; } unset($tmp); $lineParser->parse($s); $s = $el->getText(); $s = Texy::unescapeHtml($s); $s = Texy::escapeHtml($s); $s = $tx->unprotect($s); return $tx->protect($s, Texy::CONTENT_BLOCK) . "\n"; } if ($blocktype === 'block/text') { $s = trim($s, "\n"); if ($s === '') { return "\n"; } $s = Texy::escapeHtml($s); $s = str_replace("\n", TexyHtml::el('br')->startTag(), $s); // nl2br return $tx->protect($s, Texy::CONTENT_BLOCK) . "\n"; } if ($blocktype === 'block/comment') { return "\n"; } if ($blocktype === 'block/div') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('div'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/section') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('section'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/article') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('article'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/aside') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('aside'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/header') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('header'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/footer') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('footer'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } if ($blocktype === 'block/nav') { $s = Texy::outdent($s); if ($s === '') { return "\n"; } $el = TexyHtml::el('nav'); $mod->decorate($tx, $el); $el->parseBlock($tx, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } return FALSE; }
/** * Parse text in all cells. * @param TexyHtml * @return void */ private function finishPart($elPart) { $tx = $this->texy; foreach ($elPart->getChildren() as $elRow) { foreach ($elRow->getChildren() as $elCell) { if ($elCell->colSpan > 1) { $elCell->attrs['colspan'] = $elCell->colSpan; } if ($elCell->rowSpan > 1) { $elCell->attrs['rowspan'] = $elCell->rowSpan; } $text = rtrim($elCell->text); if (strpos($text, "\n") !== FALSE) { // multiline parse as block // HACK: disable tables $this->disableTables = TRUE; $elCell->parseBlock($tx, Texy::outdent($text)); $this->disableTables = FALSE; } else { $elCell->parseLine($tx, ltrim($text)); } if ($elCell->getText() === '') { $elCell->setText("\xC2\xA0"); // } } } }
public function blockHandler($invocation, $blocktype, $content, $lang, $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); //vstup se nebude zpracovavat } $highlighter = new \FSHL\Highlighter(new \FSHL\Output\HtmlManual(), \FSHL\Highlighter::OPTION_TAB_INDENT); $texy = $invocation->getTexy(); $content = \Texy::outdent($content); //Set correct lexer: switch (strtoupper($lang)) { case 'C': case 'CPP': $lexer = new \FSHL\Lexer\Cpp(); break; case 'CSS': $lexer = new \FSHL\Lexer\Css(); break; case 'HTML': $lexer = new \FSHL\Lexer\Html(); break; //HtmlOnly lexer //HtmlOnly lexer case 'JAVA': $lexer = new \FSHL\Lexer\Java(); break; case 'JS': case 'JAVASCRIPT': $lexer = new \FSHL\Lexer\Javascript(); break; case 'NEON': $lexer = new \FSHL\Lexer\Neon(); break; case 'PHP': $lexer = new \FSHL\Lexer\Php(); break; case 'PYTHON': $lexer = new \FSHL\Lexer\Python(); break; case 'SQL': $lexer = new \FSHL\Lexer\Sql(); break; case 'TEX': $lexer = new \FSHL\Lexer\Tex(); break; case 'TEXY': $lexer = new \FSHL\Lexer\Texy(); break; default: $lexer = new \FSHL\Lexer\Minimal(); } $content = $highlighter->highlight($content, $lexer); $content = $texy->protect($content, \Texy::CONTENT_BLOCK); $elPre = \TexyHtml::el('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = strtolower($lang); $elPre->create('code', $content); return $elPre; }
/** * User handler for code block * * @param TexyHandlerInvocation handler invocation * @param string block type * @param string text to highlight * @param string language * @param TexyModifier modifier * @return TexyHtml */ public function blockHandler($invocation, $blocktype, $content, $lang, $modifier) { /** @var \Texy $texy */ $texy = $invocation->getTexy(); $content = \Texy::outdent($content); $lexerData = $this->resolveLexer($blocktype); $lexer = $this->getLexerInstance($lexerData['name']); $highlighter = $this->getHighlighter($lexerData['countLines']); if ($lexer !== false) { $content = $highlighter->highlight($content, $lexer); } else { $content = htmlspecialchars($content); } $content = $texy->protect($content, \Texy::CONTENT_BLOCK); $elPre = \TexyHtml::el('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = mb_strtolower($this->getLanguage($blocktype)); $elPre->create('code', $content); return $elPre; }
function TexylaFSHLBlockHandler($invocation, $blocktype, $content, $lang, $modifier) { /** * User handler for code block by dgx * * @param TexyHandlerInvocation handler invocation * @param string block type * @param string text to highlight * @param string language * @param TexyModifier modifier * @return TexyHtml */ if ($blocktype !== 'block/code') { return $invocation->proceed(); } $lang = strtoupper($lang); if ($lang == 'JAVASCRIPT') { $lang = 'JS'; } $parser = new fshlParser('HTML_UTF8', P_TAB_INDENT); if (!$parser->isLanguage($lang)) { return $invocation->proceed(); } $texy = $invocation->getTexy(); $content = Texy::outdent($content); $content = $parser->highlightString($lang, $content); $content = $texy->protect($content, Texy::CONTENT_BLOCK); $elPre = TexyHtml::el('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = strtolower($lang); $elCode = $elPre->create('code', $content); return $elPre; }