From e13fc04c3e973da60d5f4e9cc6fc38105cd2ddf9 Mon Sep 17 00:00:00 2001 From: frozolotl <44589151+frozolotl@users.noreply.github.com> Date: Tue, 28 Mar 2023 17:04:27 +0200 Subject: Fix parsing of language in single-tick raw literals (#401) --- src/syntax/ast.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/syntax/ast.rs') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index b064da88..4abf51d9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -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); -- cgit v1.2.3