Skip to content
Closed
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
38 changes: 28 additions & 10 deletions crates/biome_html_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 19 additions & 12 deletions crates/biome_html_formatter/src/html/auxiliary/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl FormatNodeRule<HtmlElement> for FormatHtmlElement {
closing_element,
} = node.as_fields();

let closing_element = closing_element?;
let opening_element = opening_element?;
let tag_name = opening_element.name()?;
let tag_name = tag_name
Expand Down Expand Up @@ -62,9 +61,13 @@ impl FormatNodeRule<HtmlElement> for FormatHtmlElement {
.last_token()
.is_some_and(|tok| tok.has_trailing_whitespace())
|| closing_element
.l_angle_token()
.ok()
.is_some_and(|tok| tok.has_leading_whitespace_or_newline());
.as_ref()
.map(|e| {
e.l_angle_token()
.ok()
.is_some_and(|tok| tok.has_leading_whitespace_or_newline())
})
.unwrap_or_default();

// "Borrowing" in this context refers to tokens in nodes that would normally be
// formatted by that node's formatter, but are instead formatted by a sibling
Expand Down Expand Up @@ -98,7 +101,7 @@ impl FormatNodeRule<HtmlElement> for FormatHtmlElement {
None
};
let borrowed_closing_tag = if should_borrow_closing_tag {
Some(closing_element.clone())
closing_element.clone()
} else {
None
};
Expand Down Expand Up @@ -147,13 +150,17 @@ impl FormatNodeRule<HtmlElement> for FormatHtmlElement {
}
}
}
FormatNodeRule::fmt(
&FormatHtmlClosingElement::default().with_options(FormatHtmlClosingElementOptions {
tag_borrowed: should_borrow_closing_tag,
}),
&closing_element,
f,
)?;
if let Some(closing_element) = closing_element {
FormatNodeRule::fmt(
&FormatHtmlClosingElement::default().with_options(
FormatHtmlClosingElementOptions {
tag_borrowed: should_borrow_closing_tag,
},
),
&closing_element,
f,
)?;
}

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ HtmlRoot {
r_angle_token: R_ANGLE@4..5 ">" [] [],
},
children: HtmlElementList [],
closing_element: missing (required),
closing_element: missing (optional),
},
],
eof_token: EOF@5..6 "" [Newline("\n")] [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ HtmlRoot {
value_token: HTML_LITERAL@5..8 "foo" [] [],
},
],
closing_element: missing (required),
closing_element: missing (optional),
},
],
eof_token: EOF@8..9 "" [Newline("\n")] [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HtmlRoot {
r_angle_token: missing (required),
},
children: HtmlElementList [],
closing_element: missing (required),
closing_element: missing (optional),
},
],
eof_token: EOF@1..2 "" [Newline("\n")] [],
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_html_syntax/src/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/biome_html_syntax/src/generated/nodes_mut.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xtask/codegen/html.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HtmlSelfClosingElement =
HtmlElement =
opening_element: HtmlOpeningElement
children: HtmlElementList
closing_element: HtmlClosingElement
closing_element: HtmlClosingElement?


// <a href="">
Expand Down