User:DrOwl/wikiCode

From S23Wiki
Jump to: navigation, search

Discription

add a code2 tag into wiki pages using some regex and the pre tag in a custom Mediawiki extension:

its for displaying code and such like below, but with out the messing about

we need to replace out any code that wiki might process...

this is a first untestedversion with just monkey knolage of how to make it work

Symbols

symbols wiki uses and there excape codes

< = &lt;

> = &gt;

# = &#35;

[ = &#91;

\ = &#92;

{ = &#123;

| = &#124;

} = &#125;

~ = &#126;


Syntax

<code2>text</code2>

Example

<code2>some code including <b> html</b> tags and such things... </code2>

example Result

just the code form above displayed instead of "run" ie the <b> bit isnt in bold  =)


Source

<highlightSyntax> <?php

  1. code Mediawiki extension
  2. using regex
  3. by DrOwl 21.06.2005 <- a Date in the Future ,ehe ;)
  4. upDated 23.06.2006
  5. added in a few more regEx's and renamed to code2
  1. install extension hook

$wgExtensionFunctions[] = "wfCodeExtension";


  1. extension hook callback function

function wfCodeExtension() {

 global $wgParser;

 #install parser hook for <code2> tags
 $wgParser->setHook( "code2", "renderCode" );

}

function renderCode( $input ) { global $wgOutputEncoding;

if (!$input) $input = "mu"; #if no input then mu

$input =~ s/&/&/g; $input =~ s/</</g; $input =~ s/>/>/g; $input =~ s/#/#/g; $input =~ s/[/[/g; $input =~ s/]/]/g; $input =~ s/{/{/g; $input =~ s/|/|/g; $input =~ s/}/}/g; $input =~ s/~/~/g;

$output="<pre>"; $output."$input"; $output.="</pre>";

return $output;

}

?>

</highlightSyntax>