mirror of
https://github.com/typst/typst
synced 2025-06-28 00:03:17 +08:00
Fix raw block has extra space when end with backtick (#4162)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
2245e02b4e
commit
4ae376f2c7
@ -297,16 +297,12 @@ impl Lexer<'_> {
|
|||||||
self.push_raw(SyntaxKind::RawLang);
|
self.push_raw(SyntaxKind::RawLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine inner content between backticks and with trimmed
|
// Determine inner content between backticks.
|
||||||
// single spaces (line trimming comes later).
|
|
||||||
self.s.eat_if(' ');
|
self.s.eat_if(' ');
|
||||||
let mut inner = self.s.to(end - backticks);
|
let inner = self.s.to(end - backticks);
|
||||||
if inner.trim_end().ends_with('`') {
|
|
||||||
inner = inner.strip_suffix(' ').unwrap_or(inner);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine dedent level.
|
// Determine dedent level.
|
||||||
let lines = split_newlines(inner);
|
let mut lines = split_newlines(inner);
|
||||||
let dedent = lines
|
let dedent = lines
|
||||||
.iter()
|
.iter()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
@ -317,6 +313,15 @@ impl Lexer<'_> {
|
|||||||
.min()
|
.min()
|
||||||
.unwrap_or(0);
|
.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 is_whitespace = |line: &&str| line.chars().all(char::is_whitespace);
|
||||||
let starts_whitespace = lines.first().is_some_and(is_whitespace);
|
let starts_whitespace = lines.first().is_some_and(is_whitespace);
|
||||||
let ends_whitespace = lines.last().is_some_and(is_whitespace);
|
let ends_whitespace = lines.last().is_some_and(is_whitespace);
|
||||||
|
BIN
tests/ref/issue-3820-raw-space-when-end-with-backtick.png
Normal file
BIN
tests/ref/issue-3820-raw-space-when-end-with-backtick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 351 B |
@ -624,7 +624,20 @@ fn main() {
|
|||||||
|
|
||||||
~~~~The~spaces~on~this~line~shrink
|
~~~~The~spaces~on~this~line~shrink
|
||||||
|
|
||||||
|
--- issue-3820-raw-space-when-end-with-backtick ---
|
||||||
|
```typ
|
||||||
|
`code`
|
||||||
|
```
|
||||||
|
|
||||||
|
```typ
|
||||||
|
`code`
|
||||||
|
```
|
||||||
|
|
||||||
--- raw-unclosed ---
|
--- raw-unclosed ---
|
||||||
// Unterminated.
|
// Test unterminated raw text.
|
||||||
|
//
|
||||||
|
// Note: This test should be the final one in the file because it messes up
|
||||||
|
// syntax highlighting.
|
||||||
|
//
|
||||||
// Error: 1-2:1 unclosed raw text
|
// Error: 1-2:1 unclosed raw text
|
||||||
`endless
|
`endless
|
||||||
|
Loading…
x
Reference in New Issue
Block a user