@@ -34,6 +34,59 @@ fn current_node<Handle>(open_elems: &[Handle]) -> &Handle {
34
34
open_elems. last ( ) . expect ( "no current element" )
35
35
}
36
36
37
+ macro_rules! tag {
38
+ ( $( $tag: tt ) |+) => {
39
+ $( tag!( __inner: $tag) ) |+
40
+ } ;
41
+ // Named end tag
42
+ ( __inner: [ /$tag: tt] ) => {
43
+ crate :: tokenizer:: Tag { kind: crate :: tokenizer:: EndTag , name: local_name!( $tag) , .. }
44
+ } ;
45
+ // Named start tag
46
+ ( __inner: [ $tag: tt] ) => {
47
+ crate :: tokenizer:: Tag { kind: crate :: tokenizer:: StartTag , name: local_name!( $tag) , .. }
48
+ } ;
49
+ }
50
+
51
+ macro_rules! is_not_tag {
52
+ ( $input: ident, $( $tag: tt ) |+) => {
53
+ !matches!( $input, $( tag!( __inner: $tag) ) |+)
54
+ } ;
55
+ }
56
+
57
+ macro_rules! tag_token {
58
+ ( $id: ident @ $( $tag: tt ) |+) => {
59
+ crate :: tree_builder:: types:: Token :: Tag (
60
+ $id @ ( tag!( $( $tag) |+) )
61
+ )
62
+ } ;
63
+ ( $( $tag: tt) |+) => {
64
+ crate :: tree_builder:: types:: Token :: Tag (
65
+ tag!( $( $tag) |+)
66
+ )
67
+ } ;
68
+ }
69
+
70
+ macro_rules! any_end_tag {
71
+ ( ) => {
72
+ crate :: tokenizer:: Tag {
73
+ kind: crate :: tokenizer:: EndTag ,
74
+ ..
75
+ }
76
+ } ;
77
+ }
78
+
79
+ macro_rules! any_end_tag_token {
80
+ ( ) => {
81
+ any_end_tag_token!( _)
82
+ } ;
83
+ ( $tag: ident) => {
84
+ crate :: tree_builder:: types:: Token :: Tag (
85
+ $tag @ any_end_tag!( )
86
+ )
87
+ } ;
88
+ }
89
+
37
90
#[ doc( hidden) ]
38
91
impl < Handle , Sink > TreeBuilder < Handle , Sink >
39
92
where
45
98
46
99
match mode {
47
100
//§ the-initial-insertion-mode
48
- InsertionMode :: Initial => match_token ! ( token {
49
- Token :: Characters ( SplitStatus :: NotSplit , text) => ProcessResult :: SplitWhitespace ( text) ,
101
+ InsertionMode :: Initial => match token {
102
+ Token :: Characters ( SplitStatus :: NotSplit , text) => {
103
+ ProcessResult :: SplitWhitespace ( text)
104
+ } ,
50
105
Token :: Characters ( SplitStatus :: Whitespace , _) => ProcessResult :: Done ,
51
106
Token :: Comment ( text) => self . append_comment_to_doc ( text) ,
52
107
token => {
@@ -55,30 +110,53 @@ where
55
110
self . set_quirks_mode ( Quirks ) ;
56
111
}
57
112
ProcessResult :: Reprocess ( InsertionMode :: BeforeHtml , token)
58
- }
59
- } ) ,
113
+ } ,
114
+ } ,
60
115
61
116
//§ the-before-html-insertion-mode
62
- InsertionMode :: BeforeHtml => match_token ! ( token {
63
- Token :: Characters ( SplitStatus :: NotSplit , text) => ProcessResult :: SplitWhitespace ( text) ,
117
+ // InsertionMode::BeforeHtml => match_token!(token {
118
+ // Token::Characters(SplitStatus::NotSplit, text) => ProcessResult::SplitWhitespace(text),
119
+ // Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done,
120
+ // Token::Comment(text) => self.append_comment_to_doc(text),
121
+
122
+ // tag @ <html> => {
123
+ // self.create_root(tag.attrs);
124
+ // self.mode.set(InsertionMode::BeforeHead);
125
+ // ProcessResult::Done
126
+ // }
127
+
128
+ // </head> </body> </html> </br> => else,
129
+
130
+ // tag @ </_> => self.unexpected(&tag),
131
+
132
+ // token => {
133
+ // self.create_root(vec!());
134
+ // ProcessResult::Reprocess(InsertionMode::BeforeHead, token)
135
+ // }
136
+ // }),
137
+
138
+ //§ the-before-html-insertion-mode
139
+ InsertionMode :: BeforeHtml => match token {
140
+ Token :: Characters ( SplitStatus :: NotSplit , text) => {
141
+ ProcessResult :: SplitWhitespace ( text)
142
+ } ,
64
143
Token :: Characters ( SplitStatus :: Whitespace , _) => ProcessResult :: Done ,
65
144
Token :: Comment ( text) => self . append_comment_to_doc ( text) ,
66
-
67
- tag @ < html> => {
145
+ // Token::Tag(tag @ tag!(["html"] | [/"body"])) => {
146
+ tag_token ! ( tag @ [ " html" ] | [ / "body" ] ) => {
68
147
self . create_root ( tag. attrs ) ;
69
148
self . mode . set ( InsertionMode :: BeforeHead ) ;
70
149
ProcessResult :: Done
71
- }
72
-
73
- </head> </body> </html> </br> => else,
74
-
75
- tag @ </_> => self . unexpected( & tag) ,
76
-
150
+ } ,
151
+ // Token::Tag(tag @ any_end_tag!()) if !matches!(tag, tag!([/"head"] | [/"body"] | [/"html"] | [/"br"])) =>
152
+ any_end_tag_token ! ( tag) if is_not_tag ! ( tag, [ /"head" ] | [ /"body" ] | [ /"html" ] | [ /"br" ] ) => {
153
+ self . unexpected ( & tag)
154
+ } ,
77
155
token => {
78
156
self . create_root ( vec ! ( ) ) ;
79
157
ProcessResult :: Reprocess ( InsertionMode :: BeforeHead , token)
80
- }
81
- } ) ,
158
+ } ,
159
+ } ,
82
160
83
161
//§ the-before-head-insertion-mode
84
162
InsertionMode :: BeforeHead => match_token ! ( token {
0 commit comments