Fix raw block has extra space when end with backtick (#4162)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
ba1ae1c9a2
commit
c2eddff485
@ -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);
|
||||
|
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
|
||||
|
||||
--- issue-3820-raw-space-when-end-with-backtick ---
|
||||
```typ
|
||||
`code`
|
||||
```
|
||||
|
||||
```typ
|
||||
`code`
|
||||
```
|
||||
|
||||
--- 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
|
||||
`endless
|
||||
|
Loading…
Reference in New Issue
Block a user