This setting is used in demo:
$texy = new Texy\Texy;
$texy->imageModule->root = '/images/';
$texy->imageModule->linkedRoot = '/images/';
$texy->headingModule->generateID = true;
// syntax highlighting
$texy->addHandler('block', 'blockHandler');
The handler uses Prism.js to highlight syntax:
function blockHandler(
Texy\HandlerInvocation $invocation,
string $blocktype,
string $content,
string $lang,
Texy\Modifier $modifier
): Texy\HtmlElement
{
if ($blocktype !== 'block/code') {
// nothing to do
return $invocation->proceed();
}
$texy = $invocation->getTexy();
$elPre = Texy\HtmlElement::el('pre');
if ($modifier) {
$modifier->decorate($texy, $elPre);
}
$elPre->attrs['class'] = 'language-' . $lang;
$content = $texy->protect(htmlspecialchars($content), $texy::CONTENT_BLOCK);
$elPre->create('code', $content);
return $elPre;
}
In addition, when the conversion is complete, some characters are replaced by entities in the text to make them more visible:
$html = $texy->process($text);
$html = str_replace(
["\xc2\xa0", "\xc2\xad", "\xe2\x80\x93", "\xe2\x80\x94"],
[' ', '­', '–', '—'],
$html
);