====== Code Replacement Plugin ====== ---- plugin ---- description: Enhancements for the normal syntax author : Christopher Smith, LGnap email : chris@jalakai.co.uk, N/A type : syntax lastupdate : 2020-07-28 compatible : Hogfather depends : conflicts : similar : code2, code3, code tags : code, syntaxhighlight downloadurl: https://github.com/lgnap/dokuwiki-plugin-code/archive/master.zip ---- This plugin replaces the current DokuWiki handlers for ''%% %%'' & ''%% %%'' markup. It adds ability to recognize and render a title above the code box. This plugin was inspired by [[bug>477]] and my own curiosity to see if it was possible to override DokuWiki's native syntax handling. There is another [[code2|Code Plugin]] which adds line numbers, console mode and can highlight diff output. ---- See the plugin in action [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/tutorials/codeplugin|here (maybe outdated)]] (or below) ===== Syntax ===== ''%% some code %%'' \\ ''%% some text %%'' === lang === The ''lang'' parameter causes the [[wp>syntax highlighting]] according to the language you specify Supported parameters (fileextensions given if differ from lang): FIXME - this list is incomplete, please add any supported language that's not listed A full list of supported languages can be found [[http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi#Supported_languages|here]]. *actionscript ''as'' *c *cpp *csharp *css *html *ini *java *javascript ''js'' (including JSON) *nsis *php *plsql *python ''py'' *sql *xml *bash *delphi *asp.net asp *coldfusion cfm === title === Adding a ''title'' will add a small flag ontop of the codebox to enable the direct downloading of the sourcecode If no ''title'' is given the plugin will render the ''%%%%'' or ''%%%%'' markup identically to the native DokuWiki handler. ===== Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. Plugin sources: [[https://github.com/lgnap/dokuwiki-plugin-code/archive/master.zip|zip format (4k)]] ===== Details ===== The plugin consists of three files, two (almost identical) syntax plugins files, [[#syntaxcode.php|syntax/code.php]] & [[#syntaxfile.php|syntax/file.php]] and some CSS styles, [[#style.css|style.css]].sd ===== Revision History ===== * 2020-07-29 --- Fix fatal issue about function signatures, and put code on github * 2008-08-13 --- Update plugin URL * --- Add support for unknown render formats (e.g. ODT plugin) * 2006-12-17 --- Sync below darcs update into main package. * 2006-01-24 --- Minor update, darcs only (package release held until after next DokuWiki update) * replace hex entities in patterns with ''<'' & ''>'' * 2005-08-19 --- Updated, split into two plugin scripts to allow nesting of ''%%%%'' within ''%%%%'' and vice versa. Downloadable plugin package released. * 2005-08-01 --- Updated, adds //titles// to the "''%%%%''" syntax. * 2005-07-30 --- Released. ===== To Do ===== ===== Bugs ====== ===== Discussion ===== doesn't work with version 2024-02-06a "Kaos" !!! --- //[[|MaddoX]] 2024-03-4 (updated 2024-03-4)// ---- What would be nice is if it automatically generates a title based on the language attribute set if no title is explicitly set. --- //[[webmaster@lajzar.co.uk|ta' lajzar]] 2005-07-30 05:06// > Modify handle() ... if (!$lang) $lang = NULL; // add one line if (!trim($title) && $lang) $title = "Language: $lang"; // end addition } else { --- //[[chris@jalakai.co.uk|ChrisS]] 2005-07-31 (updated 2005-08-01)// ---- Can you make the class search for java code search java 1.5 (or let me config what i want as 1.6 is around the corner)? > DokuWiki uses the GeSHi syntax highlighter to provide the highlighting. Refer to DokuWiki's [[:wiki:syntax]] page and to [[http://qbnz.com/highlighter/|GeSHi]] for details. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2006-10-20 12:32// ---- Is there a list of supported code types for this plugin? That would be really handy! Cool plugin. > See [[http://qbnz.com/highlighter/|GeSHi]]. ---- Cool plug-in, but would be even better with line numbering. > See the other [[code2|Code]] plugin which provides just that.\\ --- //[[support@mwat.de|Matthias Watermann]] 2007-01-31 21:59// ---- I love this plugin, but I often find myself documenting console instructions, is it possible to add a version of the file/code but with the its black background with white writing similar to a console I guess :) just and idea or perhaps someone has all ready done this. > You might want to install the other [[code2|Code Plugin]] which provides a ''console'' mode.\\ --- //[[support@mwat.de|Matthias Watermann]] 2008/04/05 19:35// ---- Great plugin but i have an issue: if i write ${something} ... %%in a tag %% the output is ${something}|> this happen with the bash syntax highlight, but without this plugin (with the default code render) it does not happen. I've watched the HTML of the page ${something}|> Is this a bug? \\ Enrico 2008/12/16 2:16 > It doesn't happen for me, see [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/sandbox/code|test page]]. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2008/12/17 01:09// >> In your page the code is grey it is not highlighted. In my page //something// is blue and the //{}// are green. I can't figure where is the problem. Thanks for the reply. Enrico 2008/12/21 18:06 >> here it is the HTML code that i get >>

title

${something}|>
>>> The code plugin does very little. Its a wrapper around DokuWiki's code syntax to provide a title and different appearance. The syntax highlighting itself is provided by a separate module, GeSHI, included with the DokuWiki core. The code plugin doesn't change the highlighting colours, they are typically part of the template. Any different in highlighting colours may be due to a different template. All I can suggest is you update to the latest DokuWiki, the latest version of the code plugin and check that all syntax modes in the page are closed properly. Also, you may want to see how the page looks in the default template. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2008/12/25 15:13// >>>> I've already the latest DokuWiki and, I'm using the default template... by the way it can be a GeSHI bug? \\ Enrico 2009/1/4 16:00 >>>>> I have the same problem, I suspect it is a geshi issue. I checked first it wasn't other plugins by turning them all off. Still there. Turned off this plugin and just used the default code format in DokuWiki. Problem still there. Then dug through the geshi code. Line 2304 (pasted below) in inc/geshi.php causes the problem. It runs into a problem parsing the span markers when there are curly brackets in the expression (geshi uses |> as a temporary span marker) and so the HTML above is missing a closing span. preg_match_all("/<\|(?:|[^>])+>(?:(?!\|>).*?)\|>|<\/a>/", $stuff_to_parse, $highlighted_in_stuff, PREG_OFFSET_CAPTURE); >>>>> This code is embedded inside an if statement for symbol highlighting. Immediately preceding that is an if statement that handles bracket highlighting. You can fix it by moving the bracket highlighting so that it is done after the symbol highlighting - testing this now to see if I ever have other odd effects creep in because of the shift. Note, my geshi version (defined at the top of inc/geshi.php) is 1.0.7.21. \\ Snorri 2009/3/19 > Tried to update my wiki to 2009-02-14. Now the plugin produces invalid XHTML (strict) markup due open paragraph won't be closed before the (optional div) and pre tags are insert. Any idea or hint what the problem may be? \\ Gunther 2009/4/6 23:24