plugin:syntaxhighlighter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:syntaxhighlighter [2009-02-24 14:09] – suggestion about closing tag emanuele | plugin:syntaxhighlighter [2020-06-04 16:33] (current) – StarArmy | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SyntaxHighlighter Plugin ====== | ||
+ | ---- plugin ---- | ||
+ | description: | ||
+ | author | ||
+ | email : dshin@pimpsmart.com | ||
+ | type : Action, Syntax | ||
+ | lastupdate : 2008-12-04 | ||
+ | compatible : 2008-05-05, !Hogfather | ||
+ | similar | ||
+ | tags : code, syntaxhighlight, | ||
+ | downloadurl: | ||
+ | bugtracker : https:// | ||
+ | sourcerepo : https:// | ||
+ | ---- | ||
+ | |||
+ | =====Features===== | ||
+ | |||
+ | * it uses [[http:// | ||
+ | * 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: | ||
+ | |||
+ | ^ Archive | ||
+ | |||
+ | The project is hosted at [[https:// | ||
+ | |||
+ | ===== File Modifications ===== | ||
+ | |||
+ | I was not able to get the JavaScript files to load properly via the [[devel: | ||
+ | |||
+ | === inc\template.php: | ||
+ | |||
+ | < | ||
+ | function _tpl_metaheaders_action($data){ | ||
+ | foreach($data as $tag => $inst){ | ||
+ | foreach($inst as $attr){ | ||
+ | echo '<', | ||
+ | if(isset($attr[' | ||
+ | if($tag == ' | ||
+ | | ||
+ | | ||
+ | " | ||
+ | } | ||
+ | echo '>', | ||
+ | }else{ | ||
+ | echo '></', | ||
+ | } | ||
+ | echo " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | > I have had the same problem. The problem seems to a bug of all the browsers except Opera, to cheat, instead of change dokuwiki' | ||
+ | > e.g. <code php> | ||
+ | $event-> | ||
+ | " | ||
+ | " | ||
+ | ); | ||
+ | </ | ||
+ | > in this way dokuwiki will render also the </ | ||
+ | |||
+ | === JavaScript Snippet === | ||
+ | |||
+ | There needs to be a snippet of JavaScript at the end of the template to execute the HighlightAll function. | ||
+ | |||
+ | < | ||
+ | <script language=" | ||
+ | dp.SyntaxHighlighter.ClipboardSwf = '/ | ||
+ | dp.SyntaxHighlighter.HighlightAll(' | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | >I used following solution | ||
+ | >add to '' | ||
+ | >< | ||
+ | ' | ||
+ | | ||
+ | ' | ||
+ | >and add following function: | ||
+ | >< | ||
+ | | ||
+ | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | */ | ||
+ | function _hookjsprocessing (& | ||
+ | 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[" | ||
+ | |||
+ | ptln("" | ||
+ | ptln("< | ||
+ | ptln(" | ||
+ | ptln(" | ||
+ | ptln("</ | ||
+ | |||
+ | |||
+ | } | ||
+ | </ | ||
+ | >with the code change suggested above no other code changes are required | ||
+ | >8-) hth Dominik | ||
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | * General use (Default highlighting is ' | ||
+ | ''< | ||
+ | |||
+ | * Specific language - Python is chosen for this example | ||
+ | ''< | ||
+ | |||
+ | * Configurable options as specified in the [[plugin: | ||
+ | ''< | ||
+ | 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===== | ||
+ | |||
+ | ^ | ||
+ | |lang | ||
+ | |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** '' | ||
+ | |||
+ | ===== 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:// | ||
+ | |||
+ | ==== Adding/ | ||
+ | |||
+ | This can be accomplished by modifying the **//'' | ||
+ | |||
+ | === To add a language === | ||
+ | |||
+ | - Copy the shBrush{NewLanguage}.js file to the **//'' | ||
+ | - Modify the **//'' | ||
+ | - Add the following code in the **//'' | ||
+ | |||
+ | <code php> | ||
+ | | ||
+ | " | ||
+ | ); | ||
+ | </ | ||
+ | |||
+ | === To remove a language === | ||
+ | |||
+ | - Modify the **//'' | ||
+ | - Remove the $event code in the **//'' |