@@ -113,8 +113,11 @@ impl ParseRecoverable for NodeDoctype {
113
113
}
114
114
}
115
115
116
- impl ParseRecoverable for OpenTag {
117
- fn parse_recoverable ( parser : & mut RecoverableContext , input : ParseStream ) -> Option < Self > {
116
+ impl OpenTag {
117
+ pub fn parse_start_tag (
118
+ parser : & mut RecoverableContext ,
119
+ input : ParseStream ,
120
+ ) -> Option < Token ! [ <] > {
118
121
let token_lt = parser. parse_simple :: < Token ! [ <] > ( input) ?;
119
122
// Found closing tag when open tag was expected
120
123
// keep parsing it as open tag.
@@ -130,6 +133,13 @@ impl ParseRecoverable for OpenTag {
130
133
"close tag was parsed while waiting for open tag" ,
131
134
) ) ;
132
135
}
136
+ Some ( token_lt)
137
+ }
138
+ }
139
+
140
+ impl ParseRecoverable for OpenTag {
141
+ fn parse_recoverable ( parser : & mut RecoverableContext , input : ParseStream ) -> Option < Self > {
142
+ let token_lt = Self :: parse_start_tag ( parser, input) ?;
133
143
let name = parser. parse_simple ( input) ?;
134
144
let generics = parser. parse_simple ( input) ?;
135
145
@@ -149,23 +159,14 @@ impl ParseRecoverable for OpenTag {
149
159
}
150
160
}
151
161
152
- impl < C : CustomNode > ParseRecoverable for NodeElement < C > {
153
- fn parse_recoverable ( parser : & mut RecoverableContext , input : ParseStream ) -> Option < Self > {
154
- let open_tag: OpenTag = parser. parse_recoverable ( input) ?;
155
- let is_known_self_closed =
156
- |name| parser. config ( ) . always_self_closed_elements . contains ( name) ;
157
- let is_raw = |name| parser. config ( ) . raw_text_elements . contains ( name) ;
158
-
159
- let tag_name_str = & * open_tag. name . to_string ( ) ;
160
- if open_tag. is_self_closed ( ) || is_known_self_closed ( tag_name_str) {
161
- return Some ( NodeElement {
162
- open_tag,
163
- children : vec ! [ ] ,
164
- close_tag : None ,
165
- } ) ;
166
- }
167
-
168
- let ( children, close_tag) = if is_raw ( tag_name_str) {
162
+ impl < C : CustomNode > NodeElement < C > {
163
+ pub fn parse_children (
164
+ parser : & mut RecoverableContext ,
165
+ input : ParseStream ,
166
+ raw : bool ,
167
+ open_tag : & OpenTag ,
168
+ ) -> Option < ( Vec < Node < C > > , Option < CloseTag > ) > {
169
+ let ( children, close_tag) = if raw {
169
170
let ( child, closed_tag) =
170
171
parser. parse_with_ending ( input, |_, t| RawText :: from ( t) , CloseTag :: parse) ;
171
172
// don't keep empty RawText
@@ -207,11 +208,7 @@ impl<C: CustomNode> ParseRecoverable for NodeElement<C> {
207
208
}
208
209
209
210
parser. push_diagnostic ( diagnostic) ;
210
- return Some ( NodeElement {
211
- open_tag,
212
- children,
213
- close_tag : None ,
214
- } ) ;
211
+ return Some ( ( children, None ) ) ;
215
212
} ;
216
213
217
214
if close_tag. name != open_tag. name {
@@ -246,10 +243,31 @@ impl<C: CustomNode> ParseRecoverable for NodeElement<C> {
246
243
) ;
247
244
parser. push_diagnostic ( diagnostic)
248
245
}
246
+ Some ( ( children, Some ( close_tag) ) )
247
+ }
248
+ }
249
+
250
+ impl < C : CustomNode > ParseRecoverable for NodeElement < C > {
251
+ fn parse_recoverable ( parser : & mut RecoverableContext , input : ParseStream ) -> Option < Self > {
252
+ let open_tag: OpenTag = parser. parse_recoverable ( input) ?;
253
+ let is_known_self_closed =
254
+ |name| parser. config ( ) . always_self_closed_elements . contains ( name) ;
255
+ let is_raw = |name| parser. config ( ) . raw_text_elements . contains ( name) ;
256
+
257
+ let tag_name_str = & * open_tag. name . to_string ( ) ;
258
+ if open_tag. is_self_closed ( ) || is_known_self_closed ( tag_name_str) {
259
+ return Some ( NodeElement {
260
+ open_tag,
261
+ children : vec ! [ ] ,
262
+ close_tag : None ,
263
+ } ) ;
264
+ }
265
+ let ( children, close_tag) =
266
+ Self :: parse_children ( parser, input, is_raw ( tag_name_str) , & open_tag) ?;
249
267
let element = NodeElement {
250
268
open_tag,
251
269
children,
252
- close_tag : Some ( close_tag ) ,
270
+ close_tag,
253
271
} ;
254
272
Some ( element)
255
273
}
0 commit comments