-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser/html): correctly parse void elements
- Loading branch information
Showing
17 changed files
with
778 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/biome_html_parser/tests/html_specs/error/element/br-with-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span>foo<br>This text is inside br.</br>bar</span> |
164 changes: 164 additions & 0 deletions
164
crates/biome_html_parser/tests/html_specs/error/element/br-with-end.html.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
--- | ||
source: crates/biome_html_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
|
||
```html | ||
<span>foo<br>This text is inside br.</br>bar</span> | ||
``` | ||
|
||
|
||
## AST | ||
|
||
``` | ||
HtmlRoot { | ||
bom_token: missing (optional), | ||
directive: missing (optional), | ||
html: HtmlBogusElement { | ||
items: [ | ||
HtmlOpeningElement { | ||
l_angle_token: L_ANGLE@0..1 "<" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@1..5 "span" [] [], | ||
}, | ||
attributes: HtmlAttributeList [], | ||
r_angle_token: R_ANGLE@5..6 ">" [] [], | ||
}, | ||
HtmlElementList [ | ||
HtmlContent { | ||
value_token: HTML_LITERAL@6..9 "foo" [] [], | ||
}, | ||
HtmlSelfClosingElement { | ||
l_angle_token: L_ANGLE@9..10 "<" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@10..12 "br" [] [], | ||
}, | ||
attributes: HtmlAttributeList [], | ||
slash_token: missing (optional), | ||
r_angle_token: R_ANGLE@12..13 ">" [] [], | ||
}, | ||
HtmlContent { | ||
value_token: HTML_LITERAL@13..18 "This" [] [Whitespace(" ")], | ||
}, | ||
HtmlContent { | ||
value_token: HTML_LITERAL@18..23 "text" [] [Whitespace(" ")], | ||
}, | ||
HtmlContent { | ||
value_token: HTML_LITERAL@23..26 "is" [] [Whitespace(" ")], | ||
}, | ||
HtmlContent { | ||
value_token: HTML_LITERAL@26..33 "inside" [] [Whitespace(" ")], | ||
}, | ||
HtmlContent { | ||
value_token: HTML_LITERAL@33..36 "br." [] [], | ||
}, | ||
], | ||
HtmlBogusElement { | ||
items: [ | ||
L_ANGLE@36..37 "<" [] [], | ||
SLASH@37..38 "/" [] [], | ||
HtmlName { | ||
value_token: HTML_LITERAL@38..40 "br" [] [], | ||
}, | ||
R_ANGLE@40..41 ">" [] [], | ||
], | ||
}, | ||
HtmlElementList [ | ||
HtmlContent { | ||
value_token: HTML_LITERAL@41..44 "bar" [] [], | ||
}, | ||
], | ||
HtmlClosingElement { | ||
l_angle_token: L_ANGLE@44..45 "<" [] [], | ||
slash_token: SLASH@45..46 "/" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@46..50 "span" [] [], | ||
}, | ||
r_angle_token: R_ANGLE@50..51 ">" [] [], | ||
}, | ||
], | ||
}, | ||
eof_token: EOF@51..52 "" [Newline("\n")] [], | ||
} | ||
``` | ||
|
||
## CST | ||
|
||
``` | ||
0: [email protected] | ||
0: (empty) | ||
1: (empty) | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] | ||
0: [email protected] "span" [] [] | ||
2: [email protected] | ||
3: [email protected] ">" [] [] | ||
1: [email protected] | ||
0: [email protected] | ||
0: [email protected] "foo" [] [] | ||
1: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] | ||
0: [email protected] "br" [] [] | ||
2: [email protected] | ||
3: (empty) | ||
4: [email protected] ">" [] [] | ||
2: [email protected] | ||
0: [email protected] "This" [] [Whitespace(" ")] | ||
3: [email protected] | ||
0: [email protected] "text" [] [Whitespace(" ")] | ||
4: [email protected] | ||
0: [email protected] "is" [] [Whitespace(" ")] | ||
5: [email protected] | ||
0: [email protected] "inside" [] [Whitespace(" ")] | ||
6: [email protected] | ||
0: [email protected] "br." [] [] | ||
2: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] "/" [] [] | ||
2: [email protected] | ||
0: [email protected] "br" [] [] | ||
3: [email protected] ">" [] [] | ||
3: [email protected] | ||
0: [email protected] | ||
0: [email protected] "bar" [] [] | ||
4: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] "/" [] [] | ||
2: [email protected] | ||
0: [email protected] "span" [] [] | ||
3: [email protected] ">" [] [] | ||
3: [email protected] "" [Newline("\n")] [] | ||
``` | ||
|
||
## Diagnostics | ||
|
||
``` | ||
br-with-end.html:1:39 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Void elements should not have a closing tag. | ||
> 1 │ <span>foo<br>This text is inside br.</br>bar</span> | ||
│ ^^ | ||
2 │ | ||
br-with-end.html:1:37 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Expected a matching closing tag but instead found '</br>'. | ||
> 1 │ <span>foo<br>This text is inside br.</br>bar</span> | ||
│ ^^^^^ | ||
2 │ | ||
i Expected a matching closing tag here. | ||
> 1 │ <span>foo<br>This text is inside br.</br>bar</span> | ||
│ ^^^^^ | ||
2 │ | ||
``` |
1 change: 1 addition & 0 deletions
1
crates/biome_html_parser/tests/html_specs/ok/no-end-tags/br-in-span.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span>foo<br>bar</span> |
Oops, something went wrong.