summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BBCodeParser.php34
1 files changed, 34 insertions, 0 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;