SyntaxHighlighter2 Plugin

Compatible with DokuWiki

2009-02-14

plugin SyntaxHighlighter 2.x plugin for DokuWiki

Last updated on
2010-07-05
Provides
Syntax, Action
Conflicts with
syntaxhighlighter3

Download and Installation

:!: Plugin is not actively maintained (unless someone else takes over), please use SyntaxHighlighter 3 instead.

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

The subfolder sxh2 contains a complete (and untouched) distribution of SyntaxHighlighter 2.1.364.

screenshot

Syntax and Usage

Client side syntax highlighter (with copy to clipboard functionality) based on SyntaxHighlighter Plugin by David Shin. Main differences:

  • Updated to use version 2.1.364 of SyntaxHighlighter by Alex Gorbatchev.
  • Does not use <code> tags, enables parallell use with DokuWikis own server side syntax highlighter (GeSHi).

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 file name to $brushes in action.php, see plugin structure.

options - Semicolon separated options for SyntaxHighlighter, see SyntaxHighlighter Configuration.

Example:

<sxh php; first-line: 5; highlight: [10,11,12,13]; wrap-lines: true>
function render($mode, &$renderer, $data) {
 
    if ($mode == 'xhtml') {
        if (count($data) == 3) {
            list($syntax, $attr, $content) = $data;
            if ($syntax == 'sxh')
                $renderer->doc .= "<pre class=\"brush: ".$attr."\">".$renderer->_xmlEntities($content)."</pre>";
            else
                $renderer->file($content);
        }
        return true;
    }
    return false;
}
</sxh>

Copy to clipboard

Hover mouse pointer over the code, a toolbar pops up with four buttons, the second is “copy to clipboard”.

Tool tips and dialog texts can be modified but require code changes, see SyntaxHighlighter strings.

Plugin structure

These files and directories are included in the plugin:

syntaxhighlighter2/
|-- action.php
|-- sxh2
|   |-- LGPLv3.txt
|   |-- scripts
|   |   |-- clipboard.swf
|   |   |-- shBrushAS3.js
|   |   |-- shBrushBash.js
|   |   |-- shBrushCSharp.js
|   |   |-- shBrushColdFusion.js
|   |   |-- shBrushCpp.js
|   |   |-- shBrushCss.js
|   |   |-- shBrushDelphi.js
|   |   |-- shBrushDiff.js
|   |   |-- shBrushErlang.js
|   |   |-- shBrushGroovy.js
|   |   |-- shBrushJScript.js
|   |   |-- shBrushJava.js
|   |   |-- shBrushJavaFX.js
|   |   |-- shBrushPerl.js
|   |   |-- shBrushPhp.js
|   |   |-- shBrushPlain.js
|   |   |-- shBrushPowerShell.js
|   |   |-- shBrushPython.js
|   |   |-- shBrushRuby.js
|   |   |-- shBrushScala.js
|   |   |-- shBrushSql.js
|   |   |-- shBrushVb.js
|   |   |-- shBrushXml.js
|   |   |-- shCore.js
|   |   `-- shLegacy.js
|   |-- src
|   |   |-- shCore.js
|   |   `-- shLegacy.js
|   |-- styles
|   |   |-- help.png
|   |   |-- magnifier.png
|   |   |-- page_white_code.png
|   |   |-- page_white_copy.png
|   |   |-- printer.png
|   |   |-- shCore.css
|   |   |-- shThemeDefault.css
|   |   |-- shThemeDjango.css
|   |   |-- shThemeEclipse.css
|   |   |-- shThemeEmacs.css
|   |   |-- shThemeFadeToGrey.css
|   |   |-- shThemeMidnight.css
|   |   `-- shThemeRDark.css
|   `-- test.html
`-- syntax
    `-- code.php

Known issues

  • Does not look good in Mozilla Firefox, looks great in Internet Explorer 8. SyntaxHighlighter examples (tested outside DokuWiki) look like they should in Firefox. The problem seems to be a combination of stylesheets, Firefox and DokuWiki. Could be an easy fix, but I don't know. Turns out it really was an easy fix, removing 'title' attribute for SyntaxHighlighter's CSS stylesheets in action.php solved the problem.
  • Requires Flash for copy to clipboard functionality. :!: SyntaxHighlighter 3 does not use Flash.
plugin/syntaxhighlighter2.txt · Last modified: 2011/11/21 12:48 by 138.215.255.66
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate