diff --git a/crates/typst-html/src/lib.rs b/crates/typst-html/src/lib.rs
index 236a32544..aa769976e 100644
--- a/crates/typst-html/src/lib.rs
+++ b/crates/typst-html/src/lib.rs
@@ -83,8 +83,8 @@ fn html_document_impl(
)?;
let output = handle_list(&mut engine, &mut locator, children.iter().copied())?;
+ let introspector = Introspector::html(&output);
let root = root_element(output, &info)?;
- let introspector = Introspector::html(&root);
Ok(HtmlDocument { info, root, introspector })
}
diff --git a/crates/typst-library/src/introspection/introspector.rs b/crates/typst-library/src/introspection/introspector.rs
index 8cbaea891..9751dfcb8 100644
--- a/crates/typst-library/src/introspection/introspector.rs
+++ b/crates/typst-library/src/introspection/introspector.rs
@@ -10,7 +10,7 @@ use typst_utils::NonZeroExt;
use crate::diag::{bail, StrResult};
use crate::foundations::{Content, Label, Repr, Selector};
-use crate::html::{HtmlElement, HtmlNode};
+use crate::html::HtmlNode;
use crate::introspection::{Location, Tag};
use crate::layout::{Frame, FrameItem, Page, Point, Position, Transform};
use crate::model::Numbering;
@@ -55,8 +55,8 @@ impl Introspector {
/// Creates an introspector for HTML.
#[typst_macros::time(name = "introspect html")]
- pub fn html(root: &HtmlElement) -> Self {
- IntrospectorBuilder::new().build_html(root)
+ pub fn html(output: &[HtmlNode]) -> Self {
+ IntrospectorBuilder::new().build_html(output)
}
/// Iterates over all locatable elements.
@@ -392,9 +392,9 @@ impl IntrospectorBuilder {
}
/// Build an introspector for an HTML document.
- fn build_html(mut self, root: &HtmlElement) -> Introspector {
+ fn build_html(mut self, output: &[HtmlNode]) -> Introspector {
let mut elems = Vec::new();
- self.discover_in_html(&mut elems, root);
+ self.discover_in_html(&mut elems, output);
self.finalize(elems)
}
@@ -434,16 +434,16 @@ impl IntrospectorBuilder {
}
/// Processes the tags in the HTML element.
- fn discover_in_html(&mut self, sink: &mut Vec, elem: &HtmlElement) {
- for child in &elem.children {
- match child {
+ fn discover_in_html(&mut self, sink: &mut Vec, nodes: &[HtmlNode]) {
+ for node in nodes {
+ match node {
HtmlNode::Tag(tag) => self.discover_in_tag(
sink,
tag,
Position { page: NonZeroUsize::ONE, point: Point::zero() },
),
HtmlNode::Text(_, _) => {}
- HtmlNode::Element(elem) => self.discover_in_html(sink, elem),
+ HtmlNode::Element(elem) => self.discover_in_html(sink, &elem.children),
HtmlNode::Frame(frame) => self.discover_in_frame(
sink,
frame,
diff --git a/tests/ref/html/html-elem-metadata.html b/tests/ref/html/html-elem-metadata.html
new file mode 100644
index 000000000..c37a7d2ef
--- /dev/null
+++ b/tests/ref/html/html-elem-metadata.html
@@ -0,0 +1,2 @@
+
+Hi
diff --git a/tests/suite/html/elem.typ b/tests/suite/html/elem.typ
index 81ab94577..b416fdf94 100644
--- a/tests/suite/html/elem.typ
+++ b/tests/suite/html/elem.typ
@@ -5,3 +5,11 @@
// Error: 2-19 `` element must be the only element in the document
#html.elem("html")
Text
+
+--- html-elem-metadata html ---
+#html.elem("html", context {
+ let val = query().first().value
+ test(val, "Hi")
+ val
+})
+#metadata("Hi")