From 507efc3a1c14e8487705c7424d605a1663d3fe6e Mon Sep 17 00:00:00 2001 From: MALO <57839069+MDLC01@users.noreply.github.com> Date: Mon, 10 Jul 2023 18:23:14 +0200 Subject: Do not take empty lines into account when computing `raw` block dedent (#1676) --- crates/typst/src/syntax/ast.rs | 3 +++ tests/ref/text/raw.png | Bin 33809 -> 21607 bytes tests/typ/text/raw.typ | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/crates/typst/src/syntax/ast.rs b/crates/typst/src/syntax/ast.rs index 4a0de424..48be1b07 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 845f6c21..09912afc 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 8cf5ee7e..525988ec 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") -- cgit v1.2.3