Ejemplo n.º 1
0
function plugin_geshi_highlight_code($source, $options)
{
    if (!class_exists('GeSHi')) {
        require PLUGIN_GESHI_LIB_DIR . 'geshi.php';
    }
    $geshi = new GeSHi($source, $options['language']);
    $geshi->set_encoding(CONTENT_CHARSET);
    if (PLUGIN_GESHI_USE_CSS) {
        $geshi->enable_classes();
    }
    if ($options['number']) {
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->start_line_numbers_at($options['start']);
        $geshi->set_overall_class('geshi number ' . $options['language']);
        plugin_geshi_read_setting($geshi, 'default');
        plugin_geshi_read_setting($geshi, $options['language']);
        $html = $geshi->parse_code();
        if ($geshi->header_type == GESHI_HEADER_PRE) {
            $before = array('<ol', '/ol>', '</div', '> ', '  ');
            $after = array('<code><object><ol style="margin-top: 0; margin-bottom: 0;"', '/ol></object></code>', "\n</div", '>&nbsp;', ' &nbsp;');
            $html = str_replace($before, $after, $html);
        }
    } else {
        $geshi->set_overall_class('geshi ' . $options['language']);
        plugin_geshi_read_setting($geshi, 'default');
        plugin_geshi_read_setting($geshi, $options['language']);
        $html = $geshi->parse_code();
        $html = str_replace("\n&nbsp;", "\n", $html);
    }
    return $html;
}
Ejemplo n.º 2
0
function plugin_geshi_highlight_code($source, $options)
{
    if (class_exists('GeSHi') === false) {
        require PLUGIN_GESHI_LIB_DIR . 'geshi.php';
    }
    $geshi = new GeSHi($source, $options['language']);
    $geshi->set_encoding(CONTENT_CHARSET);
    if (PLUGIN_GESHI_USE_CSS) {
        $geshi->enable_classes();
    }
    $class = 'geshi';
    if (version_compare(GESHI_VERSION, '1.0.8', '<')) {
        $class .= ' ' . $options['language'];
    }
    if ($options['number']) {
        $class .= ' number';
    }
    $geshi->set_overall_class($class);
    if ($options['number']) {
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->start_line_numbers_at($options['start']);
        plugin_geshi_read_setting($geshi, 'default');
        plugin_geshi_read_setting($geshi, $options['language']);
        switch ($geshi->header_type) {
            case GESHI_HEADER_PRE:
                $before = array('<ol', '/ol>', '</div', '> ', '  ');
                $after = array('<code><object><ol style="margin-top: 0; margin-bottom: 0;"', '/ol></object></code>', "\n</div", '>&nbsp;', ' &nbsp;');
                break;
            case GESHI_HEADER_PRE_TABLE:
                $before = array("&nbsp;\n");
                $after = array("\n");
                if (PLUGIN_GESHI_USE_CSS) {
                    $before[] = '"><td class="';
                    $after[] = '"><td class="de1 ';
                } else {
                    $before[] = '"><td';
                    $after[] = '"><td style="' . $geshi->code_style . '"';
                }
                break;
        }
    } else {
        plugin_geshi_read_setting($geshi, 'default');
        plugin_geshi_read_setting($geshi, $options['language']);
        $before = array("&nbsp;\n");
        $after = array("\n");
    }
    $html = $geshi->parse_code();
    if (isset($before) && isset($after)) {
        $html = str_replace($before, $after, $html);
    }
    return $html;
}