From 7420ec972ffd6e4893fa24d12992b375da6b11fa Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 26 Jun 2025 15:20:22 +0200 Subject: [PATCH] Fix nested HTML frames (#6509) --- crates/typst-realize/src/lib.rs | 18 ++++++++++++------ tests/ref/html-frame-in-layout.png | Bin 0 -> 146 bytes tests/suite/html/frame.typ | 8 ++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 tests/ref/html-frame-in-layout.png create mode 100644 tests/suite/html/frame.typ diff --git a/crates/typst-realize/src/lib.rs b/crates/typst-realize/src/lib.rs index 7d2460a89..526f4631a 100644 --- a/crates/typst-realize/src/lib.rs +++ b/crates/typst-realize/src/lib.rs @@ -18,7 +18,7 @@ use typst_library::foundations::{ SequenceElem, Show, ShowSet, Style, StyleChain, StyledElem, Styles, SymbolElem, Synthesize, Transformation, }; -use typst_library::html::{tag, HtmlElem}; +use typst_library::html::{tag, FrameElem, HtmlElem}; use typst_library::introspection::{Locatable, SplitLocator, Tag, TagElem}; use typst_library::layout::{ AlignElem, BoxElem, HElem, InlineElem, PageElem, PagebreakElem, VElem, @@ -237,9 +237,9 @@ fn visit<'a>( return Ok(()); } - // Transformations for math content based on the realization kind. Needs + // Transformations for content based on the realization kind. Needs // to happen before show rules. - if visit_math_rules(s, content, styles)? { + if visit_kind_rules(s, content, styles)? { return Ok(()); } @@ -280,9 +280,8 @@ fn visit<'a>( Ok(()) } -// Handles special cases for math in normal content and nested equations in -// math. -fn visit_math_rules<'a>( +// Handles transformations based on the realization kind. +fn visit_kind_rules<'a>( s: &mut State<'a, '_, '_, '_>, content: &'a Content, styles: StyleChain<'a>, @@ -335,6 +334,13 @@ fn visit_math_rules<'a>( } } + if !s.kind.is_html() { + if let Some(elem) = content.to_packed::() { + visit(s, &elem.body, styles)?; + return Ok(true); + } + } + Ok(false) } diff --git a/tests/ref/html-frame-in-layout.png b/tests/ref/html-frame-in-layout.png new file mode 100644 index 0000000000000000000000000000000000000000..c3382e432a4ed17ac94d3243f428e193872d3759 GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^6+kS_0VEhE<%|3RQjwl6jv*Ddl7HAcG$dYm6xi*q zE4Ouqm00y2DT!|XbU!(X?rQs6yd6i^8}rS&E5*@W-5)zQ%$z~2UiZiU|Lynke?{9Y pefIUg@J?6<3mE7#P;qO`Pg`;!-TgGEY}Omvv4FO#lj>Gv@#R literal 0 HcmV?d00001 diff --git a/tests/suite/html/frame.typ b/tests/suite/html/frame.typ new file mode 100644 index 000000000..711933d76 --- /dev/null +++ b/tests/suite/html/frame.typ @@ -0,0 +1,8 @@ +// No proper HTML tests here yet because we don't want to test SVG export just +// yet. We'll definitely add tests at some point. + +--- html-frame-in-layout --- +// Ensure that HTML frames are transparent in layout. This is less important for +// actual paged export than for _nested_ HTML frames, which take the same code +// path. +#html.frame[A]