crazy-max / dokuwiki-plugin-syntaxhighlighter3

πŸ“ Fork of SyntaxHighlighter3 plugin for DokuWiki

Home Page:http://www.dokuwiki.org/plugin:syntaxhighlighter3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Github Release Minimum DokuWiki Version Code Quality
Become a sponsor Donate Paypal

⚠️ Abandoned project

This project is not maintained anymore and is abandoned. Feel free to fork and make your own changes if needed.

You should consider switching to SyntaxHighlighter 4 Plugin.

About

This plugin is an alternative to GeSHi server-side code highlighting of DokuWiki with client-side SyntaxHighlighter by Alex Gorbatchev with copy to clipboard functionality based on SyntaxHighlighter DokuWiki Plugin by David Shin.

The subfolder sxh3 contains an untouched build of SyntaxHighlighter 3.0.90.

For compatibility and conflicts with others plugins, please refer to the official DokuWiki SyntaxHighlighter3 plugin page.

Download and Installation

Download and install the plugin using the Plugin Manager using the download link given above. Refer to Plugins on how to install plugins manually.

If you install this plugin manually, make sure it is installed in lib/plugins/syntaxhighlighter3/. If the folder is called different it will not work!

Syntax and Usage

  • Does not use <code> tags, enables parallell use with DokuWikis own server side syntax highlighter (GeSHi).
  • Does not require Flash for copy to clipboard functionality.

Usage:

<sxh [brush alias][; options for SyntaxHighlighter]>
... code/text ...
</sxh>

Brush alias

The brush alias (language) that SyntaxHighlighter should use. Defaults to "text" if none is provided. See SyntaxHighlighter Brushes for a complete list of available brushes.
Add new brushes to the scripts directory and the alias(es) and brush file name to the available brushes string in Config Manager (example: "...,bat cmd shBrushBat.js"). The brush file name is case sensitive.

Options

Semicolon separated options for SyntaxHighlighter, see SyntaxHighlighter Configuration.
Block Title isn't a normal configuration option, but the plugin handles it as if it was, i.e. title: <title string>;.

Do not collapse code and hide the toolbar at the same time, title will not show.

Defaults

Some Syntaxhighlighter defaults can be overrided via the Config Manager :

  • auto-links: Allows you to turn detection of links in the highlighted element on and off. If the option is turned off, URLs won’t be clickable (default on)
  • collapse: Allows you to force highlighted elements on the page to be collapsed by default (default off)
  • first-line: Allows you to change the first (starting) line number (default 1)
  • gutter: Allows you to turn gutter with line numbers on and off (default on)
  • html-script: Allows you to highlight a mixture of HTML/XML code and a script which is very common in web development. Setting this value to true requires that you have shBrushXml.js loaded and that the brush you are using supports this feature (default off)
  • smart-tabs: Allows you to turn smart tabs feature on and off (default on)
  • tab-size: Allows you to adjust tab size (default 4)
  • toolbar: Toggles toolbar on/off (default on)

Example

<sxh php; first-line: 70; highlight: [89,92]; title: New title attribute in action>
    public function render($mode, &$renderer, $data) {
 
        if($mode != 'xhtml') return false;
 
        if (count($data) == 3) {
            list($syntax, $attr, $content) = $data;
            if ($syntax == 'sxh') {
                // Check if there's a title in the attribute string. It can't be passed along as a normal parameter to SyntaxHighlighter.
                if (preg_match("/title:/i", $attr)) {
                    // Extract title(s) from attribute string.
                    $attr_array = explode(";",$attr);
                    $title_array = preg_grep("/title:/i", $attr_array);
                    // Extract everything BUT title(s) from attribute string.
                    $not_title_array =  preg_grep("/title:/i", $attr_array, PREG_GREP_INVERT);
                    $attr = implode(";",$not_title_array);
                    // If there are several titles, use the last one.
                    $title = array_pop($title_array);
                    $title = preg_replace("/.*title:\s{0,}(.*)/i","$1",$title);
                    // Add title as an attribute to the <pre /> tag.
                    $renderer->doc .= "<pre class=\"brush: ".$attr."\" title=\"".$title."\">".$renderer->_xmlEntities($content)."</pre>";
                } else {
                    // No title detected, pass all attributes as parameters to SyntaxHighlighter.
                    $renderer->doc .= "<pre class=\"brush: ".$attr."\">".$renderer->_xmlEntities($content)."</pre>";
                }
             } else {
                $renderer->file($content);
            }
        }
 
        return true;
    }
</sxh>

Expected result:

Features

Copy to clipboard

Double click anywhere inside SyntaxHighlighter code area to highlight the text and then copy it using Ctrl/Cmd+C or mouse right click > Copy.
Click outside the code area to restore highlighting.

Highlight a range of lines

Example:

<sxh php; highlight: [9-18]>
// Check highlight attr for lines ranges
if (preg_match("/highlight:/i", $attr, $matches)) {
    // Extract highlight from $attr string.
    $attr_array = explode(";",$attr);
    $highlight_array = preg_grep("/highlight:/i", $attr_array);
    // Extract everything BUT highlight from $attr string.
    $not_highlight_array = preg_grep("/highlight:/i", $attr_array, PREG_GREP_INVERT);
    $attr = implode(";",$not_highlight_array);
    // If there are multiple hightlights, use the last one.
    $highlight_str = array_pop($highlight_array);
    $highlight_str = preg_replace("/.*highlight:\s{0,}(.*)/i","$1", $highlight_str);
    // Remove [ ]
    $highlight_str = str_replace(array('[', ']'), '', $highlight_str);
    // Process ranges if exists
    $highlight_exp = explode(',', $highlight_str);
    foreach ($highlight_exp as $highlight_elt) {
        if (!empty($highlight)) {
            $highlight .= ',';
        }
        $highlight_elt = trim($highlight_elt);
        $highlight_elt_exp = explode('-', $highlight_elt);
        if (count($highlight_elt_exp) == 2) {
            foreach (range($highlight_elt_exp[0], $highlight_elt_exp[1]) as $key => $lineNumber) {
                if ($key > 0) {
                    $highlight .= ',';
                }
                $highlight .= $lineNumber;
            }
        } else {
            $highlight .= $highlight_elt;
        }
    }
    $highlight = ' highlight: [' . $highlight . ']';
}
</sxh>

Expected result:

Issues and Features

Changelog

See CHANGELOG.md.

How can I help ?

All kinds of contributions are welcome πŸ™Œ! The most basic way to show your support is to star 🌟 the project, or to raise issues πŸ’¬ You can also support this project by becoming a sponsor on GitHub πŸ‘ or by making a Paypal donation to ensure this journey continues indefinitely! πŸš€

Thanks again for your support, it is much appreciated! πŸ™

License

This is a modified version (fork) of SyntaxHighlighter3 Plugin for DokuWiki based on Daniel Lindgren's work.

GPLv2. See LICENSE for more details.

About

πŸ“ Fork of SyntaxHighlighter3 plugin for DokuWiki

http://www.dokuwiki.org/plugin:syntaxhighlighter3

License:Other


Languages

Language:CSS 48.2%Language:HTML 41.1%Language:PHP 6.0%Language:JavaScript 2.7%Language:CoffeeScript 2.1%