/** * Finish invocation. * @return HtmlElement|string|FALSE */ public function solve(Texy\HandlerInvocation $invocation, $blocktype, $s, $param, Texy\Modifier $mod) { $texy = $this->texy; $parser = $invocation->getParser(); if ($blocktype === 'block/texy') { $el = new HtmlElement(); $el->parseBlock($texy, $s, $parser->isIndented()); return $el; } if (empty($texy->allowed[$blocktype])) { return FALSE; } if ($blocktype === 'block/texysource') { $s = Helpers::outdent($s); if ($s === '') { return "\n"; } $el = new HtmlElement(); if ($param === 'line') { $el->parseLine($texy, $s); } else { $el->parseBlock($texy, $s); } $s = $el->toHtml($texy); $blocktype = 'block/code'; $param = 'html'; // to be continue (as block/code) } if ($blocktype === 'block/code') { $s = Helpers::outdent($s); if ($s === '') { return "\n"; } $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); $s = $texy->protect($s, $texy::CONTENT_BLOCK); $el = new HtmlElement('pre'); $mod->decorate($texy, $el); $el->attrs['class'][] = $param; // lang $el->create('code', $s); return $el; } if ($blocktype === 'block/default') { $s = Helpers::outdent($s); if ($s === '') { return "\n"; } $el = new HtmlElement('pre'); $mod->decorate($texy, $el); $el->attrs['class'][] = $param; // lang $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); $s = $texy->protect($s, $texy::CONTENT_BLOCK); $el->setText($s); return $el; } if ($blocktype === 'block/pre') { $s = Helpers::outdent($s); if ($s === '') { return "\n"; } $el = new HtmlElement('pre'); $mod->decorate($texy, $el); $lineParser = new Texy\LineParser($texy, $el); // special mode - parse only html tags $tmp = $lineParser->patterns; $lineParser->patterns = []; 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 = html_entity_decode($s, ENT_QUOTES, 'UTF-8'); $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); $s = $texy->unprotect($s); $s = $texy->protect($s, $texy::CONTENT_BLOCK); $el->setText($s); return $el; } if ($blocktype === 'block/html') { $s = trim($s, "\n"); if ($s === '') { return "\n"; } $el = new HtmlElement(); $lineParser = new Texy\LineParser($texy, $el); // special mode - parse only html tags $tmp = $lineParser->patterns; $lineParser->patterns = []; 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 = html_entity_decode($s, ENT_QUOTES, 'UTF-8'); $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); $s = $texy->unprotect($s); return $texy->protect($s, $texy::CONTENT_BLOCK) . "\n"; } if ($blocktype === 'block/text') { $s = trim($s, "\n"); if ($s === '') { return "\n"; } $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); $s = str_replace("\n", (new HtmlElement('br'))->startTag(), $s); // nl2br return $texy->protect($s, $texy::CONTENT_BLOCK) . "\n"; } if ($blocktype === 'block/comment') { return "\n"; } if ($blocktype === 'block/div') { $s = Helpers::outdent($s, TRUE); if ($s === '') { return "\n"; } $el = new HtmlElement('div'); $mod->decorate($texy, $el); $el->parseBlock($texy, $s, $parser->isIndented()); // TODO: INDENT or NORMAL ? return $el; } return FALSE; }