diff options
| author | MALO <57839069+MDLC01@users.noreply.github.com> | 2023-07-10 18:23:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-10 18:23:14 +0200 |
| commit | 507efc3a1c14e8487705c7424d605a1663d3fe6e (patch) | |
| tree | c37a61c0d363fa3d813d7dd6a143dd43968e728c | |
| parent | 78f96f844bc54c5385c1efda0b5faad3c49fa79b (diff) | |
Do not take empty lines into account when computing `raw` block dedent (#1676)
| -rw-r--r-- | crates/typst/src/syntax/ast.rs | 3 | ||||
| -rw-r--r-- | tests/ref/text/raw.png | bin | 33809 -> 21607 bytes | |||
| -rw-r--r-- | tests/typ/text/raw.typ | 20 |
3 files changed, 23 insertions, 0 deletions
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 Binary files differindex 845f6c21..09912afc 100644 --- a/tests/ref/text/raw.png +++ b/tests/ref/text/raw.png 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 @@ -5,6 +5,10 @@ `A``B` --- +// Empty raw block. +Empty raw block:``. + +--- // Typst syntax inside. ```typ #let x = 1``` \ ```typ #f(1)``` @@ -49,6 +53,22 @@ The keyword ```rust let```. ``` --- +// 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") `Roboto` |
