SyntaxHighlighter Plugin ported from SyntaxHighlighter 1.5.1 created by Alex Gorbatchev.
Compatible with DokuWiki
2008-05-05
Similar to code, code2, code3, highlightjs, jquery-syntax, syntaxhighlighter2, syntaxhighlighter3
Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.
The project is hosted at GitHub. Public Git Repository
I was not able to get the JavaScript files to load properly via the Action Plugin. To get it to work, I had to modify the _tpl_metaheaders_action function in the inc\template.php file. The change I made was to use '></$tag>' as the closure tag instead of '/>'.
function _tpl_metaheaders_action($data){
foreach($data as $tag => $inst){
foreach($inst as $attr){
echo '<',$tag,' ',buildAttributes($attr);
if(isset($attr['_data'])){
if($tag == 'script' && $attr['_data']) {
$attr['_data'] = "<!--//--><![CDATA[//><!--\n".
$attr['_data'].
"\n//--><!]]>";
}
echo '>',$attr['_data'],'</',$tag,'>';
}else{
echo '></',$tag,'>';
}
echo "\n";
}
}
}
I have had the same problem. The problem seems to a bug of all the browsers except Opera, to cheat, instead of change dokuwiki's functions, you can add an empty “_data” parameter to the array you use to add the js file:
e.g.$event->data["script"][] = array ("type" => "text/javascript", "src" => DOKU_BASE."lib/plugins/syntaxhighlighter/Uncompressed/shCore.js", "_data" => "" );
in this way dokuwiki will render also the </$tag> and the problema is gone (at least for me…).
There needs to be a snippet of JavaScript at the end of the template to execute the HighlightAll function. I've placed the following code at the end of my lib/tpl/default/footer.html file. If someone can put this in the action.php script, this would be greatly appreciated. I do not know what action to trigger on to add the JavaScript snippet to the end of the template.
<script language="javascript">
dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
I used following solution
add tofunction register(&$controller):
$controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, '_hookjsprocessing');
and add following function:
/** * Inject the SyntaxHightlighter javascript processing * * @author David Shin <dshin@pimpsmart.com> * @param $event object target event * @param $param mixed event parameters passed from register_hook * */ function _hookjsprocessing (&$event, $param) { global $ID; global $INFO; //this ensures that code will be written only on base page //not on other inlined wiki pages (e.g. when using monobook template) if ($ID != $INFO["id"]) return; ptln(""); ptln("<script language='javascript'>"); ptln(" dp.SyntaxHighlighter.ClipboardSwf = '" .DOKU_BASE. "lib/plugins/syntaxhighlighter/Scripts/clipboard.swf';"); ptln(" dp.SyntaxHighlighter.HighlightAll('code');"); ptln("</script>"); }
with the code change suggested above no other code changes are required
hth Dominik
<code> some code </code>
<code python> some code </code>
<code firstline[10]:collapse> some code </code>
The options are passed together with the alias and are separated by a colon : character. This is how SyntaxHighlight is configured (Also I was too lazy to program it to use spaces instead of ':')
| Options | |
|---|---|
| lang | Language specified by the Language Alias. |
| nogutter | Will display no gutter. |
| nocontrols | Will display no controls at the top. |
| collapse | Will collapse the block by default. |
| firstline[value] | Will begin line count at value. Default value is 1. |
| showcolumns | Will show row columns in the first line. |
The options are passed together with the alias and are separated by a colon : character.
Warning: Do not use nocontrols and collapse together. You will not be able to expand the code
| Language | Aliases |
|---|---|
| C++ | cpp, c, c++ |
| C# | c#, c-sharp, csharp |
| CSS | css |
| Delphi | delphi, pascal |
| Java | java |
| Java Script | js, jscript, javascript |
| PHP | php |
| Python | py, python |
| Ruby | rb, ruby, rails, ror |
| Sql | sql |
| VB | vb, vb.net |
| XML/HTML | xml, html, xhtml, xslt |
Please refer to the language aliases page at Google Code for user contributed languages.
This can be accomplished by modifying the lib/plugins/syntaxhighlighter/action.php file.
lib/plugins/syntaxhighlighter/Uncompressed folder.lib/plugins/syntaxhighlighter/action.php file._hooksh function: $event->data["script"][] = array ("type" => "text/javascript",
"src" => DOKU_BASE."lib/plugins/syntaxhighlighter/Uncompressed/shBrush{NewLanguage}.js"
);
lib/plugins/syntaxhighlighter/action.php file._hooksh function for the language to be removed.