File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ export default class Parser {
66
66
// We've already built some text. Add it as a text node.
67
67
const textNode = new TextNode ( currentText ) ;
68
68
currentStack [ currentStack . length - 1 ] . addChild ( textNode ) ;
69
+ currentText = "" ;
69
70
}
70
71
} else {
71
72
// We're building text, and we found a character other than "[".
@@ -85,6 +86,8 @@ export default class Parser {
85
86
const previousStackElement = currentStack [ currentStack . length - 1 ] ;
86
87
previousStackElement . addChild ( lastStackElement ) ;
87
88
}
89
+ } else if ( nextCharacter === "/" && ! currentTagName ) {
90
+ buildingClosingTag = true ;
88
91
} else if ( ( [ "]" , " " , "=" ] . includes ( nextCharacter ) ) ) {
89
92
// We found a character that signifies the end of the tag name.
90
93
// First, we determine if it is a valid tag name.
@@ -113,6 +116,10 @@ export default class Parser {
113
116
throw new Error ( `Expected closing tag for '${ currentTagName } ', found '${ lastElement . name } '.` ) ;
114
117
} else {
115
118
currentStack [ currentStack . length - 1 ] . addChild ( lastElement ) ;
119
+ buildingText = true ;
120
+ buildingClosingTag = false ;
121
+ buildingTagName = false ;
122
+ currentTagName = "" ;
116
123
}
117
124
} else {
118
125
// Simple tag, there are no attributes or values. We push a tag to the stack and continue.
Original file line number Diff line number Diff line change @@ -19,4 +19,18 @@ describe("bbcode-ast tests", () => {
19
19
expect ( ( ( parsed . children [ 0 ] as Node ) . children [ 0 ] as TextNode ) . text ) . to . equal ( "Hello world!" ) ;
20
20
expect ( parsed . toString ( ) ) . to . equal ( "[b]Hello world![/b]" ) ;
21
21
} )
22
+
23
+ it ( "Should parse multiple simple tags" , ( ) => {
24
+ const parsed = defaultParser . parse ( "[b]Hello world![/b][i]Hello world![/i]" )
25
+ expect ( parsed . children . length ) . to . equal ( 2 ) ;
26
+ expect ( parsed . children [ 0 ] . name ) . to . equal ( "b" ) ;
27
+ expect ( ( parsed . children [ 0 ] as Node ) . children . length ) . to . equal ( 1 ) ;
28
+ expect ( ( parsed . children [ 0 ] as Node ) . children [ 0 ] . name ) . to . equal ( "TextNode" ) ;
29
+ expect ( ( ( parsed . children [ 0 ] as Node ) . children [ 0 ] as TextNode ) . text ) . to . equal ( "Hello world!" ) ;
30
+ expect ( parsed . children [ 1 ] . name ) . to . equal ( "i" ) ;
31
+ expect ( ( parsed . children [ 1 ] as Node ) . children . length ) . to . equal ( 1 ) ;
32
+ expect ( ( parsed . children [ 1 ] as Node ) . children [ 0 ] . name ) . to . equal ( "TextNode" ) ;
33
+ expect ( ( ( parsed . children [ 1 ] as Node ) . children [ 0 ] as TextNode ) . text ) . to . equal ( "Hello world!" ) ;
34
+ expect ( parsed . toString ( ) ) . to . equal ( "[b]Hello world![/b][i]Hello world![/i]" ) ;
35
+ } )
22
36
} )
You can’t perform that action at this time.
0 commit comments