Indice

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

Sintassi

<code lang 123 |[fh] text |[sh]>
{code to highlight}
</code>

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 …

<code>
some text
and more
</code>

This just renders the given preformatted text without any spe­cial high­ligh­ting. However,

<code 1>
some text
and more
</code>

will add line numbers in front of each line starting (in this case) with 1 (one).

<code JavaScript 12|Listing 2>
var de = function() {
	return (typeof(window.de) == 'object') ? window.de : {};
}();
</code>

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:

<div class="code">
  <pre class="code javascript">
  <span class="lno">12:</span>  <span class="kw2">var</span> de = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="lno">13:</span>      <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw1">typeof</span><span class="br0">&#40;</span>window.<span class="me1">de</span><span class="br0">&#41;</span> == <span class="st0">'object'</span><span class="br0">&#41;</span> ? window.<span class="me1">de</span> : <span class="br0">&#123;</span><span class="br0">&#125;</span>;
  <span class="lno">14:</span>  <span class="br0">&#125;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
  </pre>
  <p class="codefoot"><a name="listing_2">Listing 2</a></p>
</div>

If you'd rather the text above the code you'd just insert a “h” right after the pipe character i.e. “<code javascript 12|h Listing 2>”.

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”) format5). 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:

<code diff>
        --- 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])) {
</code>

To summarize:

1)
or “t” for “top”
2)
or “b” for “bottom”
3)
for “show”, the default
4)
for “hide”
5)
Meaning, that line numbering is not available for “diff”. It wouldn't make any sense any­way. Just think about it.