summaryrefslogtreecommitdiff
path: root/src/parse/parser.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-09-30 18:59:33 +0200
committerLaurenz <laurmaedje@gmail.com>2020-09-30 18:59:33 +0200
commit4077a7c11ea19b1b6b6b6fe3014b9018846cf21b (patch)
tree70e4c891c2c660b4136890cebbae7c375fe36c05 /src/parse/parser.rs
parent7cc279f7ae122f4c40592004dde89792c636b3c8 (diff)
Refactor raw blocks 💱
Diffstat (limited to 'src/parse/parser.rs')
-rw-r--r--src/parse/parser.rs35
1 files changed, 11 insertions, 24 deletions
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())),