DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:syntaxhighlighter2

This is an old revision of the document!


SyntaxHighlighter2 Plugin

Compatible with DokuWiki

2009-02-14 and newer (older not tested)

plugin SyntaxHighlighter 2.x plugin for DokuWiki

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

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to code, code2, code3, syntaxhighlighter, syntaxhighlighter3, syntaxhighlighter4

Tagged with code, highlight, syntax

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.

Discussions

I installed the plugin as of 2010-06-29, but it doesn't work correctly. The line numbers and toolbar are displayed, so I guess the plugin is loaded at least. But it does not highlight any code. I tried with a different theme in action.php, but it does not make any effect. What's wrong?

— First of all, have you read “known issues” above? Secondly, you have to provide information about browser used and DokuWiki version.

— 2010-07-05: If the problem was Firefox/Chrome related, it has been fixed. Remove old plugin and download again using link on top of this page.

plugin/syntaxhighlighter2.1307861135.txt.gz · Last modified: 2011-06-12 08:45 by 95.109.40.41

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki