Fix parsing of language in single-tick raw literals (#401)

This commit is contained in:
frozolotl 2023-03-28 17:04:27 +02:00 committed by GitHub
parent d1ff94a3b5
commit e13fc04c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -581,7 +581,14 @@ impl Raw {
/// An optional identifier specifying the language to syntax-highlight in.
pub fn lang(&self) -> Option<&str> {
let inner = self.0.text().trim_start_matches('`');
let text = self.0.text();
// Only blocky literals are supposed to contain a language.
if !text.starts_with("```") {
return Option::None;
}
let inner = text.trim_start_matches('`');
let mut s = Scanner::new(inner);
s.eat_if(is_id_start).then(|| {
s.eat_while(is_id_continue);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -37,6 +37,10 @@ The keyword ```rust let```.
(``` trimmed ```) \
(``` trimmed```) \
---
// Single ticks should not have a language.
`rust let`
---
// First line is not dedented and leading space is still possible.
``` A