mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
HTML export: fix elem counting on classify_output (#5910)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
3744c99b07
commit
36d83c8c09
@ -307,18 +307,18 @@ fn head_element(info: &DocumentInfo) -> HtmlElement {
|
||||
|
||||
/// Determine which kind of output the user generated.
|
||||
fn classify_output(mut output: Vec<HtmlNode>) -> SourceResult<OutputKind> {
|
||||
let len = output.len();
|
||||
let count = output.iter().filter(|node| !matches!(node, HtmlNode::Tag(_))).count();
|
||||
for node in &mut output {
|
||||
let HtmlNode::Element(elem) = node else { continue };
|
||||
let tag = elem.tag;
|
||||
let mut take = || std::mem::replace(elem, HtmlElement::new(tag::html));
|
||||
match (tag, len) {
|
||||
match (tag, count) {
|
||||
(tag::html, 1) => return Ok(OutputKind::Html(take())),
|
||||
(tag::body, 1) => return Ok(OutputKind::Body(take())),
|
||||
(tag::html | tag::body, _) => bail!(
|
||||
elem.span,
|
||||
"`{}` element must be the only element in the document",
|
||||
elem.tag
|
||||
elem.tag,
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
|
2
tests/ref/html/html-elem-alone-context.html
Normal file
2
tests/ref/html/html-elem-alone-context.html
Normal file
@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html>
|
||||
<html></html>
|
7
tests/suite/html/elem.typ
Normal file
7
tests/suite/html/elem.typ
Normal file
@ -0,0 +1,7 @@
|
||||
--- html-elem-alone-context html ---
|
||||
#context html.elem("html")
|
||||
|
||||
--- html-elem-not-alone html ---
|
||||
// Error: 2-19 `<html>` element must be the only element in the document
|
||||
#html.elem("html")
|
||||
Text
|
Loading…
x
Reference in New Issue
Block a user