Exemple #1
0
/**
 * User handler for unknown reference
 * @return Texy\HtmlElement|string
 */
function newReferenceHandler(Texy\HandlerInvocation $parser, $refName)
{
    $names = ['Me', 'Punkrats', 'Servats', 'Bonifats'];
    if (!isset($names[$refName])) {
        return FALSE;
        // it's not my job
    }
    $name = $names[$refName];
    $el = new Texy\HtmlElement('a');
    $el->attrs['href'] = '#comm-' . $refName;
    // set link destination
    $el->attrs['class'][] = 'comment';
    // set class name
    $el->attrs['rel'] = 'nofollow';
    // enable rel="nofollow"
    $el->setText("[{$refName}] {$name}:");
    // set link label (with Texy formatting)
    return $el;
}
Exemple #2
0
/**
 * 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();
    }
    $texy = $invocation->getTexy();
    global $geshiPath;
    if ($lang == 'html') {
        $lang = 'html4strict';
    }
    $content = Texy\Helpers::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 = new Texy\HtmlElement();
    $el->setText($content);
    return $el;
}