diff options
author | uckelman <uckelman@nomic.net> | 2010-04-25 17:10:18 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-04-25 17:10:18 +0000 |
commit | 17e5654c1583939217c31f876419bc2f6d6edc43 (patch) | |
tree | 5007bc1c666df94971dd8cafec79103040f6f857 | |
parent | 0021abab9556142d13ec771baeacbad5c3440b41 (diff) |
Added list handling.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6742 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r-- | src/BBCodeParser.php | 34 | ||||
-rw-r--r-- | test/BBCodeParserTest.php | 3 |
2 files changed, 36 insertions, 1 deletions
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; diff --git a/test/BBCodeParserTest.php b/test/BBCodeParserTest.php index 41cb0c5..f1047f9 100644 --- a/test/BBCodeParserTest.php +++ b/test/BBCodeParserTest.php @@ -17,7 +17,8 @@ class BBCodeParserTest extends PHPUnit_Framework_TestCase { public function providerParse() { return array( array('', '3i2cqt66', '', null), - array('[b:3i2cqt66]This is a[/b:3i2cqt66] test of [i:3i2cqt66]the BBCode[/i:3i2cqt66] parser. Will [u:3i2cqt66][i:3i2cqt66]it[/i:3i2cqt66][/u:3i2cqt66] parse? Also, throw in some difficult characters: 1 < 2 < 4 > 3.', '3i2cqt66', '__This is a__ test of _the BBCode_ parser. Will __it__ parse? Also, throw in some difficult characters: 1 < 2 < 4 > 3.', null) + array('[b:3i2cqt66]This is a[/b:3i2cqt66] test of [i:3i2cqt66]the BBCode[/i:3i2cqt66] parser. Will [u:3i2cqt66][i:3i2cqt66]it[/i:3i2cqt66][/u:3i2cqt66] parse? Also, throw in some difficult characters: 1 < 2 < 4 > 3.', '3i2cqt66', '__This is a__ test of _the BBCode_ parser. Will __it__ parse? Also, throw in some difficult characters: 1 < 2 < 4 > 3.', null), + array("Foo\n[list=2:11cx3qbi]\n[*:11cx3qbi] first[/*:m:11cx3qbi]\n[*:11cx3qbi] second[/*:m:11cx3qbi][/list:o:11cx3qbi]\nBar", '11cx3qbi', "Foo\n\n * first\n * second\n\nBar", null) ); } } |