summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src
diff options
context:
space:
mode:
authorWenzhuo Liu <mgt@oi-wiki.org>2024-05-17 16:35:51 +0800
committerGitHub <noreply@github.com>2024-05-17 08:35:51 +0000
commit4ae376f2c7ba9621479640afbe45936c6c859cff (patch)
tree207dcf6b2f90937fa72f79ec1f33a64baa6bae08 /crates/typst-syntax/src
parent2245e02b4eacfba158e5557f31c05a5fcab151a9 (diff)
Fix raw block has extra space when end with backtick (#4162)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-syntax/src')
-rw-r--r--crates/typst-syntax/src/lexer.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs
index 97aa94d2..6719deaf 100644
--- a/crates/typst-syntax/src/lexer.rs
+++ b/crates/typst-syntax/src/lexer.rs
@@ -297,16 +297,12 @@ impl Lexer<'_> {
self.push_raw(SyntaxKind::RawLang);
}
- // Determine inner content between backticks and with trimmed
- // single spaces (line trimming comes later).
+ // Determine inner content between backticks.
self.s.eat_if(' ');
- let mut inner = self.s.to(end - backticks);
- if inner.trim_end().ends_with('`') {
- inner = inner.strip_suffix(' ').unwrap_or(inner);
- }
+ let inner = self.s.to(end - backticks);
// Determine dedent level.
- let lines = split_newlines(inner);
+ let mut lines = split_newlines(inner);
let dedent = lines
.iter()
.skip(1)
@@ -317,6 +313,15 @@ impl Lexer<'_> {
.min()
.unwrap_or(0);
+ // Trim single space in last line if text ends with a backtick. The last
+ // line is the one directly before the closing backticks and if it is
+ // just whitespace, it will be completely trimmed below.
+ if inner.trim_end().ends_with('`') {
+ if let Some(last) = lines.last_mut() {
+ *last = last.strip_suffix(' ').unwrap_or(last);
+ }
+ }
+
let is_whitespace = |line: &&str| line.chars().all(char::is_whitespace);
let starts_whitespace = lines.first().is_some_and(is_whitespace);
let ends_whitespace = lines.last().is_some_and(is_whitespace);