From: Pierre Habouzit (MadCoder Date: Tue, 1 Feb 2005 20:13:32 +0000 (+0000) Subject: make our wiki class a little more configureable : ability to disable hr, img, and... X-Git-Tag: xorg/old~329 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=5c9398ae9ed8c567173df1f087376ae828027e0d;p=platal.git make our wiki class a little more configureable : ability to disable hr, img, and h1-3 git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-429 --- diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 83c0474..f8d8b6f 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -116,6 +116,13 @@ class XOrgWikiAST class XOrgWikiParser { + // {{{ properties + + var $max_title_level = 3; + var $enable_img = true; + var $enable_hr = true; + + // }}} // {{{ constructor function XOrgWikiParser() @@ -143,14 +150,26 @@ class XOrgWikiParser function _analyse(&$line) { - $modes = Array('!'=>'h1', '!!'=>'h2', '!!!'=>'h3', '>'=>'blockquote', '.'=>'pre', '-'=>'ul', '#'=>'ol'); $types = Array(); + $modes = Array( '>'=>'blockquote', '.'=>'pre', '-'=>'ul', '#'=>'ol'); + + for ($i = 1; $i <= $this->max_title_level; $i++) { + $modes[str_pad('!', $i, '!')] = "h$i"; + } + /* non - nesting blocks */ - if (preg_match('/^(!!?!?|[.>])/', $line, $m)) { + $hre = $this->max_title_level ? str_pad('!', $this->max_title_level * 2 - 1, '!?') : ''; + + if (preg_match("/^($hre|[.>])/", $line, $m)) { $types[] = $modes[$m[1]]; return Array($types, substr($line, strlen($m[1]))); } + /* hr */ + if ($this->enable_hr && $line == '----') { + return Array(Array('hr'), ''); + } + /* nesting blocks */ $pos = 0; while ($line{$pos} == '-' || $line{$pos} == '#') { @@ -161,8 +180,6 @@ class XOrgWikiParser /* nesting blocks or special lines */ if ($pos) { return Array($types, substr($line, $pos)); - } elseif ($line == '----') { - return Array(Array('hr'), ''); } elseif ($line) { return Array(Array('p'), $line); } else { @@ -235,7 +252,7 @@ class XOrgWikiParser case '\\': if ($i + 1 < $len) { - if (strpos('*/_@[()', $d = $line{$i+1}) !== false) { + if (strpos('*/_{}[()', $d = $line{$i+1}) !== false) { $cur .= $d; $i += 2; break; @@ -248,10 +265,9 @@ class XOrgWikiParser case '*': case '/': case '_': - case '@': if (preg_match(",^[$c][$c](.*?[^\\\\])[$c][$c],", substr($line, $i), $m)) { $lexm[] = $cur; - $type = ($c == '*' ? 'strong' : ($c == '/' ? 'em' : ($c == '@' ? 'tt' : 'u'))); + $type = ($c == '*' ? 'strong' : ($c == '/' ? 'em' : 'u')); $lexm[] = new XOrgWikiAST($type, $this->_parse_line($m[1])); $cur = ''; $i += strlen($m[0]); @@ -261,8 +277,23 @@ class XOrgWikiParser $i ++; break; - case '[': + case '{': + if (preg_match(",^{{(.*?[^\\\\])}},", substr($line, $i), $m)) { + $lexm[] = $cur; + $lexm[] = new XOrgWikiAST('tt', $this->_parse_line($m[1])); + $cur = ''; + $i += strlen($m[0]); + break; + } + $cur .= $line{$i}; + $i ++; + break; + case '(': + if (!$this->enable_img) { + break; + } + case '[': $re = ( $c=='[' ? ',^\[([^|]*)\|([^]]*)\],' : ',^\(([^|]*)\|([^)]*)\),' ); if (preg_match($re, substr($line, $i), $m)) { $lexm[] = $cur; @@ -319,6 +350,9 @@ class XOrgWikiToText function _render($AST, $idt, $list, $fst) { $res = ''; + if ($AST->type == 'hr') { + return "\n ---------------------------------------------------------------------- "; + } if (strpos('|br|div|p|pre|h1|h2|h3|li|', "|{$AST->type}|")!==false && !$fst) { $res .= "\n$idt"; }