====== SyntaxHighlighter Plugin ====== ---- plugin ---- description: SyntaxHighlighter Plugin ported from SyntaxHighlighter 1.5.1 created by Alex Gorbatchev. author : David Shin email : dshin@pimpsmart.com type : Action, Syntax lastupdate : 2008-12-04 compatible : 2008-05-05, !Hogfather similar : code, code2, code3 tags : code, syntaxhighlight, syntax downloadurl: https://github.com/dshin/dokuwiki-syntaxhighlighter/raw/master/syntaxhighlighter.tar.gz bugtracker : https://github.com/dshin/dokuwiki-syntaxhighlighter/issues sourcerepo : https://github.com/dshin/dokuwiki-syntaxhighlighter ---- =====Features===== * it uses [[http://code.google.com/p/syntaxhighlighter/|SyntaxHighlighter]] to do code coloring on the **client side** * new languages can be added by adding new stylesheets * configurable start line number and line number toggling (no gutter) * line numbers do not mess up copy/paste operations * configurable controls * collapse code blocks on initial load via configuration option * plain view mode * copy all code in a block in one click with clipboard copy button * show column numbers (somewhat buggy) ===== Download and Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. ^ Archive | [[https://github.com/dshin/dokuwiki-syntaxhighlighter/raw/master/syntaxhighlighter.tar.gz|SyntaxHighlighter v1.0 (32Kb, tar.gz)]] | The project is hosted at [[https://github.com/dshin/dokuwiki-syntaxhighlighter/tree|GitHub]]. [[git://github.com/dshin/dokuwiki-syntaxhighlighter.git|Public Git Repository]] ===== File Modifications ===== I was not able to get the JavaScript files to load properly via the [[devel:action_plugins|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 **//'''>'''//** as the closure tag instead of **//'''/>'''//**. === inc\template.php:357 === 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'] = ""; } echo '>',$attr['_data'],''; }else{ echo '>'; } 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 and the problema is gone (at least for me...). === JavaScript Snippet === 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. >I used following solution >add to ''function register(Doku_Event_Handler $controller)'': > $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, '_hookjsprocessing'); >and add following function: > /** * Inject the SyntaxHightlighter javascript processing * * @author David Shin * @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(""); } >with the code change suggested above no other code changes are required >8-) hth Dominik ===== Usage ===== * General use (Default highlighting is 'html') '' some code '' * Specific language - Python is chosen for this example '' some code '' * Configurable options as specified in the [[plugin:syntaxhighlighter#configuration_options|Configuration Options]] section. First line at 10 and initial collapse '' some 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 ':') =====Configuration Options===== ^ Options ^^ |lang |Language specified by the [[plugin:syntaxhighlighter#language_aliases|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 ===== ^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 [[http://code.google.com/p/syntaxhighlighter/wiki/Languages|language aliases]] page at Google Code for user contributed languages. ==== Adding/Removing Languages ==== This can be accomplished by modifying the **//''lib/plugins/syntaxhighlighter/action.php''//** file. === To add a language === - Copy the shBrush{NewLanguage}.js file to the **//''lib/plugins/syntaxhighlighter/Uncompressed''//** folder. - Modify the **//''lib/plugins/syntaxhighlighter/action.php''//** file. - Add the following code in the **//''_hooksh''//** function: $event->data["script"][] = array ("type" => "text/javascript", "src" => DOKU_BASE."lib/plugins/syntaxhighlighter/Uncompressed/shBrush{NewLanguage}.js" ); === To remove a language === - Modify the **//''lib/plugins/syntaxhighlighter/action.php''//** file. - Remove the $event code in the **//''_hooksh''//** function for the language to be removed.