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