Edit

Konfigurace dema

Toto nastavení se používá v demu:

$texy = new Texy\Texy;

$texy->imageModule->root = '/images/';
$texy->imageModule->linkedRoot = '/images/';
$texy->headingModule->generateID = TRUE;

// syntax highlighting
$texy->addHandler('block', 'blockHandler');

Handler pro zvýrazňování syntaxe používá knihovnu FSHL:

/**
 * User handler for code block
 *
 * @param Texy\HandlerInvocation  handler invocation
 * @param string  block type
 * @param string  text to highlight
 * @param string  language
 * @param Texy\Modifier modifier
 * @return Texy\HtmlElement
 */
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
    if ($blocktype !== 'block/code') {
        // nothing to do
        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\Helpers::outdent($content);
    $content = $parser->highlightString($lang, $content);
    $content = $texy->protect($content, $texy::CONTENT_BLOCK);

    $elPre = Texy\HtmlElement::el('pre');
    if ($modifier) $modifier->decorate($texy, $elPre);
    $elPre->attrs['class'] = strtolower($lang);

    $elCode = $elPre->create('code', $content);

    return $elPre;
}

Po dokončení konverze se navíc v textu zamění některé znaky za entity, aby byly lépe patrné:

$html = $texy->process($text);

$html = str_replace(
    ["\xc2\xa0", "\xc2\xad", "\xe2\x80\x93", "\xe2\x80\x94"],
    [' ', '­', '–', '—'],
    $html
);