-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser,format/html): add CDATA sections (#4859)
- Loading branch information
Showing
21 changed files
with
450 additions
and
5 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.
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
23 changes: 23 additions & 0 deletions
23
crates/biome_html_formatter/src/html/auxiliary/cdata_section.rs
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,23 @@ | ||
use crate::prelude::*; | ||
use biome_formatter::write; | ||
use biome_html_syntax::{HtmlCdataSection, HtmlCdataSectionFields}; | ||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatHtmlCdataSection; | ||
impl FormatNodeRule<HtmlCdataSection> for FormatHtmlCdataSection { | ||
fn fmt_fields(&self, node: &HtmlCdataSection, f: &mut HtmlFormatter) -> FormatResult<()> { | ||
let HtmlCdataSectionFields { | ||
cdata_start_token, | ||
content_token, | ||
cdata_end_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
cdata_start_token.format(), | ||
content_token.format(), | ||
cdata_end_token.format() | ||
] | ||
) | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<![CDATA[example]]> | ||
<![CDATA[1<3]]> | ||
<![CDATA[lorem ipsum dolar 33 bottles of beer on the wall, 33 bottles of beer! Take one down, pass it around ...]]> | ||
<![CDATA[<div attributes="some-attribute"></div>]]> |
73 changes: 73 additions & 0 deletions
73
crates/biome_html_parser/tests/html_specs/ok/cdata.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,73 @@ | ||
--- | ||
source: crates/biome_html_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
|
||
```html | ||
<![CDATA[example]]> | ||
<![CDATA[1<3]]> | ||
<![CDATA[lorem ipsum dolar 33 bottles of beer on the wall, 33 bottles of beer! Take one down, pass it around ...]]> | ||
<![CDATA[<div attributes="some-attribute"></div>]]> | ||
``` | ||
|
||
|
||
## AST | ||
|
||
``` | ||
HtmlRoot { | ||
bom_token: missing (optional), | ||
directive: missing (optional), | ||
html: HtmlElementList [ | ||
HtmlCdataSection { | ||
cdata_start_token: CDATA_START@0..9 "<![CDATA[" [] [], | ||
content_token: HTML_LITERAL@9..16 "example" [] [], | ||
cdata_end_token: CDATA_END@16..19 "]]>" [] [], | ||
}, | ||
HtmlCdataSection { | ||
cdata_start_token: CDATA_START@19..29 "<![CDATA[" [Newline("\n")] [], | ||
content_token: HTML_LITERAL@29..32 "1<3" [] [], | ||
cdata_end_token: CDATA_END@32..35 "]]>" [] [], | ||
}, | ||
HtmlCdataSection { | ||
cdata_start_token: CDATA_START@35..45 "<![CDATA[" [Newline("\n")] [], | ||
content_token: HTML_LITERAL@45..148 "lorem ipsum dolar 33 bottles of beer on the wall, 33 bottles of beer! Take one down, pass it around ..." [] [], | ||
cdata_end_token: CDATA_END@148..151 "]]>" [] [], | ||
}, | ||
HtmlCdataSection { | ||
cdata_start_token: CDATA_START@151..161 "<![CDATA[" [Newline("\n")] [], | ||
content_token: HTML_LITERAL@161..200 "<div attributes=\"some-attribute\"></div>" [] [], | ||
cdata_end_token: CDATA_END@200..203 "]]>" [] [], | ||
}, | ||
], | ||
eof_token: EOF@203..204 "" [Newline("\n")] [], | ||
} | ||
``` | ||
|
||
## CST | ||
|
||
``` | ||
0: [email protected] | ||
0: (empty) | ||
1: (empty) | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] "<![CDATA[" [] [] | ||
1: [email protected] "example" [] [] | ||
2: [email protected] "]]>" [] [] | ||
1: [email protected] | ||
0: [email protected] "<![CDATA[" [Newline("\n")] [] | ||
1: [email protected] "1<3" [] [] | ||
2: [email protected] "]]>" [] [] | ||
2: [email protected] | ||
0: [email protected] "<![CDATA[" [Newline("\n")] [] | ||
1: [email protected] "lorem ipsum dolar 33 bottles of beer on the wall, 33 bottles of beer! Take one down, pass it around ..." [] [] | ||
2: [email protected] "]]>" [] [] | ||
3: [email protected] | ||
0: [email protected] "<![CDATA[" [Newline("\n")] [] | ||
1: [email protected] "<div attributes=\"some-attribute\"></div>" [] [] | ||
2: [email protected] "]]>" [] [] | ||
3: [email protected] "" [Newline("\n")] [] | ||
``` |
Oops, something went wrong.