From 4077a7c11ea19b1b6b6b6fe3014b9018846cf21b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 30 Sep 2020 18:59:33 +0200 Subject: =?UTF-8?q?Refactor=20raw=20blocks=20=F0=9F=92=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parse/parser.rs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'src/parse/parser.rs') diff --git a/src/parse/parser.rs b/src/parse/parser.rs index bbd7ee1d..3446af83 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -99,35 +99,22 @@ impl Parser<'_> { self.parse_heading().map(SyntaxNode::Heading) } - Token::Raw { raw, terminated } => { + Token::Raw { raw, backticks, terminated } => { if !terminated { - error!(@self.feedback, end, "expected backtick"); + error!(@self.feedback, end, "expected backtick(s)"); } - self.with_span(SyntaxNode::Raw(unescape_raw(raw))) - } - Token::Code { lang, raw, terminated } => { - if !terminated { - error!(@self.feedback, end, "expected backticks"); - } - - let lang = lang.and_then(|lang| { - if let Some(ident) = Ident::new(lang.v) { - Some(ident.span_with(lang.span)) - } else { - error!(@self.feedback, lang.span, "invalid identifier"); - None + let raw = if backticks > 1 { + process_raw(raw) + } else { + Raw { + lang: None, + lines: split_lines(raw), + inline: true, } - }); - - let mut lines = unescape_code(raw); - let block = lines.len() > 1; - - if lines.last().map(|s| s.is_empty()).unwrap_or(false) { - lines.pop(); - } + }; - self.with_span(SyntaxNode::Code(Code { lang, lines, block })) + self.with_span(SyntaxNode::Raw(raw)) } Token::Text(text) => self.with_span(SyntaxNode::Text(text.to_string())), -- cgit v1.2.3