Tcl in wiki2xhtml ?
Par obi, Friday 29 April 2005 à 14:42 :: Linux and Libre Software :: #63 :: rss
Need to display some some tcl code while keeping the freedom of wiki edition ? As simple as using one Macrowiki. Of course, it's easy to add other languages.
The String and Comment part are quite naïve, but I'm not very trained with regexps, and by the way all the TCL I've written works with theses rules. Feel free to send a patch if you have a more complete version.
function wikiTcl($text,$args) {
$patterns = array();
$htmls = array();
//Strings
array_push($patterns,"'\"(.*)\"'");
array_push($htmls, '<em class="string">"${1}"</em>');
//Comments
array_push($patterns,"'#(.*)'");
array_push($htmls, '<em class="comment">#${1}</em>');
//Keyword stuff
$keywords = array ("after", "append", "array", "bgerror", "binary", "break", "catch","cd", "clock", "close", "concat", "continue","dde", "encoding", "eof", "error", "eval", "exec", "exit", "expr", "fblocked", "fconfigure", "fcopy", "file", "fileevent", "filename", "flush", "for", "foreach", "format", "gets", "glob", "global", "history", "http", "if", "incr", "info", "interp", "join", "lappend", "library", "lindex", "linsert", "list", "llength", "load", "lrange", "lreplace", "lsearch", "lset", "lsort", "memory", "msgcat", "namespace", "open", "package", "parray", "pid", "proc", "puts", "pwd", "re_syntax", "read", "regexp", "registry", "regsub", "rename", "resource", "return", "scan", "seek", "set", "socket", "source", "split", "string", "subst", "switch", "tcltest", "tclvars", "tell", "time", "trace", "unknown", "unset", "update", "uplevel", "upvar", "variable", "vwait", "while" );
foreach ($keywords as $k) {
array_push($patterns, "'(\040|\n|\t)".$k."(\040|\n|\t)'");
array_push($htmls, '${1}<strong class="'.$k.'">'.$k.'</strong>${2}');
}
$ret = preg_replace($patterns, $htmls, $text);
return '<pre><code class="tcl">'. $ret . "</code></pre>";
}
Do not forget to register the function:
$wiki = new wiki2xhtml();
$wiki->registerFunction('macro:tcl','wikiTcl');
Then to effeclty write TCL code:
///tcl
#'############################################################
#' Build Configuration list
#'############################################################
proc BuildConfigurationListMapProc { resultListConf configuration } {
upvar $resultListConf configurationList
#'set confName Get $configuration "name"
#'lappend configurationList $confName
lappend configurationList $configuration
return 1
}
///
Et voilà.

Merci olivier !
Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.