====== Code2 Plugin ====== ===== Informazioni generali ===== Questo plugin rimpiazza quello già presente nella dokuwiki consentendo di visualizzare i numeri di riga e la possibilita di aggiungere una riga di intestazione ed una di chiusura. Include anche l'evidenziazione per la sintassi Diff. **Sito:** [[http://wiki.splitbrain.org/plugin:code2 | http://wiki.splitbrain.org/plugin:code2]] ===== Sintassi ===== {code to highlight} * "''lang''" (if present) specifies the given code's (programming-) language; * "''123''" (if present) specifies the first number to use when numbering the given code's lines; * the first "''%%|%%''" (if present) delimits the first argument(s) from the remaining ones which are used to produce a //header// or //footer// above/below the high­ligh­ted code; * a "''h''" (for //"header"//)((or "''t''" for //"top"//)) following //immediately// the pipe cha­rac­ter cau­ses the remaining "''text''" to get placed //above// the code, a "''f''" (for //"footer"//)((or "''b''" for //"bottom"//)) places the "''text''" below the code (note that this flag is //optional//; if omitted it de­faults to "''f''"); * the "''text''" is used as-is with the additional benefit of get­ting wrapped by an anchor tag which allows for addressing the code from other pages. * the second "''%%|%%''" (if present) delimits the header/footer text; * a "''s''"((for //"show"//, the default)) or "''h''"((for //"hide"//)) character (if present) controls the code block's initial folding state; for more details see the [[#folding_state|Behaviour]] section below. * the "''{code to highlight}''" is either the plain text to process or a pointer to an [[#external_files|external source]]. ===== Examples ===== Please note that you will //not// see any highlighting //here//: This section just shows some use cases with­out actually triggering the activation of the plugin -- even if it was installed ... some text and more This just renders the given preformatted text without any spe­cial high­ligh­ting. However, some text and more will add line numbers in front of each line starting (in this case) with ''1'' (one). var de = function() { return (typeof(window.de) == 'object') ? window.de : {}; }(); This markup will turn on both the JavaScript syntax highlighting and the line num­be­ring star­ting in this case with num­ber ''12'' and place the text "''Listing 2''" below the code block -- pro­du­cing HTML like:
  12:  var de = function() {
  13:      return (typeof(window.de) == 'object') ? window.de : {};
  14:  }();
  

Listing 2

If you'd rather the text //above// the code you'd just insert a "''h''" right after the pipe character i.e. "''%%%%''". Of course, instead of ''javascript'' you may use any other highlighting mode sup­por­ted by //GeSHi// like "''html''" for exam­ple or "''php''". In case a lan­gua­ge is gi­ven which is //not// sup­por­ted by //GeSHi// there won't be any syn­tax high­ligh­ting, of course, but the line num­bers (if re­que­sted) and hea­der/foo­ter li­nes (if re­que­sted) will ap­pear ne­ver­the­less. As men­tio­ned abo­ve be­si­des the line num­be­ring fea­tu­re this plugin pro­vi­des an im­pro­ved high­ligh­ting mode for "''diff''" files (aka "''pat­ches''"). For "''diff''" the second argument can be either __''u''__ (for "//unified//"), __''c''__ (for "//con­text//"), __''n''__ (or __''r''__ for //RCS//) or __''s''__ (for "//simple//") format((Meaning, that line numbering is //not// available for "''diff''". It wouldn't make any sense any­way. Just think about it.)). Although ap­pre­ciated this ar­gu­ment is optional as well. Omitting it will cause the plugin to per­form some ad­di­tio­nal tests to figure out the "''diff''" for­mat ac­tu­ally used. A little sample: --- syntax_plugin_code.php.orig 2007-02-23 11:33:35.000000000 +0100 +++ syntax_plugin_code.php 2007-02-23 11:53:17.000000000 +0100 @@ -595,14 +595,14 @@ $n = (int)$hits[5]; } // if if (isset($hits[7]) && ($hits[7])) { - $hits[6] = (isset($hits[6])) ? strtolower($hits[6]) . 'f' : 'f'; + $hits[6] = (isset($hits[6])) ? strtolower($hits[6]) . 'h' : 'h'; switch ($hits[6]{0}) { - case 'h': - case 't': - $ht = trim($hits[7]); + case 'b': + case 'f': + $ft = trim($hits[7]); break; default: - $ft = trim($hits[7]); + $ht = trim($hits[7]); break; } // switch if (isset($hits[8])) { To summarize: * Without the new arguments nothing changes from what you're used to know (and get) -- but see the [[#Notes]] section below. * Giving a numeric argument //only// results in preformatted text without high­ligh­ting but line numbering turned on. * Giving just a language argument turns on syntax highlighting w/o line num­bers. * Giving a language //and// a numeric argument turns on syntax highlighting //and// line numbering starting with the given number. * Adding a "''|''", optionally followed by "''h''" or "''f''" and some text will result in a header or footer line attached to the code block (see [[#Behaviour]] below).