Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-zoos-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed an issue where the Biome HTML parser would emit a parse error when certain keywords are inside the text of HTML tags.
17 changes: 16 additions & 1 deletion crates/biome_html_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn parse_doc_type(p: &mut HtmlParser) -> ParsedSyntax {
/// will emit diagnostics. We want to allow them if they have no special meaning.
#[inline(always)]
fn inside_tag_context(p: &HtmlParser) -> HtmlLexContext {
if p.options().vue {
if HtmlSyntaxFeatures::Vue.is_supported(p) {
HtmlLexContext::InsideTagVue
} else {
HtmlLexContext::InsideTag
Expand Down Expand Up @@ -181,7 +181,14 @@ fn parse_element(p: &mut HtmlParser) -> ParsedSyntax {
HtmlLexContext::Regular
},
);

let opening = m.complete(p, HTML_OPENING_ELEMENT);

// if the lexer found a keyword, rewind and lex as text
if is_at_keyword(p) {
p.re_lex(HtmlReLexContext::HtmlText);
}

if is_embedded_language_tag {
// embedded language tags always have 1 element as content
let list = p.start();
Expand Down Expand Up @@ -683,3 +690,11 @@ impl TextExpression {
Present(m.complete(p, HTML_TEXT_EXPRESSION))
}
}

fn is_at_keyword(p: &mut HtmlParser) -> bool {
is_at_svelte_keyword(p) || is_at_html_keyword(p)
}

fn is_at_html_keyword(p: &mut HtmlParser) -> bool {
matches!(p.cur(), T![html] | T![doctype])
}
16 changes: 16 additions & 0 deletions crates/biome_html_parser/tests/html_specs/ok/text_keywords.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<span>html entity</span>
<span>debug </span>
<span>attach </span>
<span>const </span>
<span>render </span>
<span>html </span>
<span>key </span>
<span>if </span>
<span>else </span>
<span>each </span>
<span>as </span>
<span>await </span>
<span>then </span>
<span>catch </span>
<span>snippet </span>
<span>doctype </span>
Loading