Turn non-empty void element into export error

This commit is contained in:
Laurenz 2025-06-23 14:22:09 +02:00
parent c1b2aee1a9
commit 9050ee1639
3 changed files with 7 additions and 3 deletions

View File

@ -89,6 +89,9 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
w.buf.push('>');
if tag::is_void(element.tag) {
if !element.children.is_empty() {
bail!(element.span, "HTML void elements must not have children");
}
return Ok(());
}

View File

@ -180,9 +180,6 @@ fn handle(
if let Some(body) = elem.body(styles) {
children = html_fragment(engine, body, locator.next(&elem.span()), styles)?;
}
if tag::is_void(elem.tag) && !children.is_empty() {
bail!(elem.span(), "HTML void elements may not have children");
}
let element = HtmlElement {
tag: elem.tag,
attrs: elem.attrs(styles).clone(),

View File

@ -1,3 +1,7 @@
--- html-non-char html ---
// Error: 1-9 the character `"\u{fdd0}"` cannot be encoded in HTML
\u{fdd0}
--- html-void-element-with-children html ---
// Error: 2-27 HTML void elements must not have children
#html.elem("img", [Hello])