From 17e5654c1583939217c31f876419bc2f6d6edc43 Mon Sep 17 00:00:00 2001 From: uckelman Date: Sun, 25 Apr 2010 17:10:18 +0000 Subject: Added list handling. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6742 67b53d14-2c14-4ace-a08f-0dab2b34000c --- src/BBCodeParser.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src') diff --git a/src/BBCodeParser.php b/src/BBCodeParser.php index 1e57e1b..85f4cc7 100644 --- a/src/BBCodeParser.php +++ b/src/BBCodeParser.php @@ -8,9 +8,11 @@ class BBCodeParser { const DONE = 3; + function parse($in, $uid) { $arg_stack = array(); + $contents_stack = array(); $fn_number = 1; $fn = array(); @@ -18,6 +20,9 @@ class BBCodeParser { $i = 0; $len = strlen($in); + $indent = ''; + $list_conter_stack = array(); + $out = ''; $state = self::TEXT; @@ -82,8 +87,34 @@ class BBCodeParser { case 'code': break; case 'list': + $out .= "\n"; + $indent .= ' '; + + switch ($arg) { + case '1': $list_counter_stack[] = 1; break; + case 'a': $list_counter_stack[] = 'a'; break; + default: $list_counter_stack[] = '*'; break; + } + break; case '*': + $out .= "\n" . $indent; + + $c = array_pop($list_counter_stack); + if ($c == '*') { + } + else if (is_int($c)) { + $out .= $c . '. '; + $list_counter_stack[] = $c + 1; + } + else if ($c == '*') { + $out .= $c . ' '; + $list_counter_stack[] = '*'; + } + else { + $out .= $c . '. '; + $list_counter_stack[] = chr(ord($c)+1); + } break; case 'img': break; @@ -124,6 +155,9 @@ class BBCodeParser { case 'code': break; case 'list': + $out .= "\n"; + $indent = substr($indent, -1); + array_pop($list_counter_stack); break; case '*': break; -- cgit v1.2.3