From 04b8b3195fbbcb8c3aa9ab22a358241580c2d6d5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 4 Aug 2025 15:21:27 +0200 Subject: [PATCH] Wrap raw blocks in `` tag additionally to `
` tag
 (#6701)

---
 crates/typst-html/src/rules.rs | 11 +++++++++--
 tests/ref/html/raw-html.html   | 11 +++++++++++
 tests/suite/text/raw.typ       |  7 +++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/html/raw-html.html

diff --git a/crates/typst-html/src/rules.rs b/crates/typst-html/src/rules.rs
index c358a181..acf9046c 100644
--- a/crates/typst-html/src/rules.rs
+++ b/crates/typst-html/src/rules.rs
@@ -415,9 +415,16 @@ const RAW_RULE: ShowFn = |elem, _, styles| {
         seq.push(line.clone().pack());
     }
 
-    Ok(HtmlElem::new(if elem.block.get(styles) { tag::pre } else { tag::code })
+    let code = HtmlElem::new(tag::code)
         .with_body(Some(Content::sequence(seq)))
-        .pack())
+        .pack()
+        .spanned(elem.span());
+
+    Ok(if elem.block.get(styles) {
+        HtmlElem::new(tag::pre).with_body(Some(code)).pack()
+    } else {
+        code
+    })
 };
 
 const RAW_LINE_RULE: ShowFn = |elem, _, _| Ok(elem.body.clone());
diff --git a/tests/ref/html/raw-html.html b/tests/ref/html/raw-html.html
new file mode 100644
index 00000000..2df62ca8
--- /dev/null
+++ b/tests/ref/html/raw-html.html
@@ -0,0 +1,11 @@
+
+
+  
+    
+    
+  
+  
+    

This is *inline*.

+
#set text(blue)
*Hello* _world_!
+ + diff --git a/tests/suite/text/raw.typ b/tests/suite/text/raw.typ index 97e77ada..79a1c000 100644 --- a/tests/suite/text/raw.typ +++ b/tests/suite/text/raw.typ @@ -487,6 +487,13 @@ test assert.eq(block, c.input.block, message: "in point " + c.name + ", expect " + repr(block) + ", got " + repr(c.input.block) + "") } +--- raw-html html --- +This is ```typ *inline*```. +```typ +#set text(blue) +*Hello* _world_! +``` + --- raw-line --- #set page(width: 200pt)