@@ -8,8 +8,10 @@ export default class Processor {
8
8
static BASE_RE = / \{ \: [ ] * ( [ ^ \} \n ] [ ^ \} \n ] * ) [ ] * \} / ;
9
9
static BLOCK_RE = / \n [ ] * \{ \: ? [ ] * ( [ ^ \} \n ] [ ^ \} \n ] * ) [ ] * \} [ ] * $ / ;
10
10
11
+ constructor ( private topLevelElement : HTMLElement ) { }
12
+
11
13
static parse ( el : HTMLElement ) {
12
- return new Processor ( ) . recurseAndParseElements ( el ) ;
14
+ return new Processor ( el ) . recurseAndParseElements ( el ) ;
13
15
}
14
16
15
17
/**
@@ -61,8 +63,6 @@ export default class Processor {
61
63
for ( let pair of trys ) {
62
64
if ( ! pair || ! pair . length ) continue ;
63
65
64
-
65
-
66
66
//#id
67
67
/* if (pair.charAt(0) === idChar) {
68
68
attrs.push(["id", pair.slice(1)]);
@@ -103,20 +103,33 @@ export default class Processor {
103
103
104
104
// Text content of this node and *not* the children.
105
105
const text = this . getTopLevelText ( el ) ;
106
+ console . log ( "🚀 ~ file: processor.ts ~ line 102 ~ el" , text ) ;
106
107
107
108
if ( Processor . BLOCK_RE . test ( text ) ) {
108
109
// Attributes should apply to the whole block.
110
+
111
+ let element = el ;
112
+ if ( el instanceof HTMLLIElement ) {
113
+ // Need to apply attributes to containing UL if HTMLLIElement has a block attribute
114
+ element = el . parentElement ;
115
+ }
116
+
109
117
let [ original , attribute_string ] =
110
- text . match ( Processor . BASE_RE ) ?? [ ] ;
118
+ text . match ( Processor . BLOCK_RE ) ?? [ ] ;
111
119
elements . push ( {
112
- element : el ,
120
+ element : element ,
113
121
attributes : this . getAttrs ( attribute_string ) ,
114
122
text : attribute_string
115
123
} ) ;
116
124
el . innerHTML = el . innerHTML . replace ( original , "" ) ;
125
+
126
+ //rerun parser if LI element to get inlines
127
+ if ( el instanceof HTMLLIElement ) {
128
+ elements . push ( ...this . recurseAndParseElements ( el ) ) ;
129
+ }
117
130
} else if ( Processor . BASE_RE . test ( text ) ) {
118
131
// Attributes are inline.
119
-
132
+ console . log ( Processor . BASE_RE . test ( text ) ) ;
120
133
// Get the text nodes that contains the attribute string.
121
134
let textNode = Array . from ( el . childNodes ) . find (
122
135
( node ) =>
@@ -134,6 +147,10 @@ export default class Processor {
134
147
135
148
// Collapsible elements are a special case due to the collapse handle.
136
149
if ( sibling && sibling . hasClass ( "collapse-indicator" ) ) {
150
+ console . log (
151
+ "🚀 ~ file: processor.ts ~ line 150 ~ Processor.BASE_RE.test(text)" ,
152
+ Processor . BASE_RE . test ( text )
153
+ ) ;
137
154
sibling = sibling . parentElement ;
138
155
}
139
156
0 commit comments