diff --git a/crates/typst/src/syntax/ast.rs b/crates/typst/src/syntax/ast.rs index 4a0de424d..48be1b07f 100644 --- a/crates/typst/src/syntax/ast.rs +++ b/crates/typst/src/syntax/ast.rs @@ -565,6 +565,9 @@ impl Raw { let dedent = lines .iter() .skip(1) + .filter(|line| !line.chars().all(char::is_whitespace)) + // The line with the closing ``` is always taken into account + .chain(lines.last()) .map(|line| line.chars().take_while(|c| c.is_whitespace()).count()) .min() .unwrap_or(0); diff --git a/tests/ref/text/raw.png b/tests/ref/text/raw.png index 845f6c211..09912afcc 100644 Binary files a/tests/ref/text/raw.png and b/tests/ref/text/raw.png differ diff --git a/tests/typ/text/raw.typ b/tests/typ/text/raw.typ index 8cf5ee7e5..525988ec1 100644 --- a/tests/typ/text/raw.typ +++ b/tests/typ/text/raw.typ @@ -4,6 +4,10 @@ // No extra space. `A``B` +--- +// Empty raw block. +Empty raw block:``. + --- // Typst syntax inside. ```typ #let x = 1``` \ @@ -48,6 +52,22 @@ The keyword ```rust let```. C ``` +--- +// Do not take empty lines into account when computing dedent. +``` + A + + B +``` + +--- +// Take last line into account when computing dedent. +``` + A + + B + ``` + --- // Text show rule #show raw: set text(font: "Roboto")