summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2022-04-12 13:00:34 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-12 22:35:04 +0200
commit072543fc59582eacfd9446055639c4427e707941 (patch)
tree37cdefe123e24f1342fad0b385615d1e2e04a350 /src/parse
parentc3a387b8f7086fc6d58a4175e8408fbbf375f5f2 (diff)
Introduce `NodeKind::Quote`
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/mod.rs1
-rw-r--r--src/parse/tokens.rs15
2 files changed, 10 insertions, 6 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 6d1985e0..92e86450 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -215,6 +215,7 @@ fn markup_node(p: &mut Parser, at_start: &mut bool) {
| NodeKind::NonBreakingSpace
| NodeKind::EnDash
| NodeKind::EmDash
+ | NodeKind::Quote(_)
| NodeKind::Linebreak
| NodeKind::Raw(_)
| NodeKind::Math(_)
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index 40ea134e..a98ef264 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -143,11 +143,13 @@ impl<'s> Tokens<'s> {
// Markup.
'~' => NodeKind::NonBreakingSpace,
+ '-' => self.hyph(),
+ '\'' => NodeKind::Quote(false),
+ '"' => NodeKind::Quote(true),
'*' if !self.in_word() => NodeKind::Star,
'_' if !self.in_word() => NodeKind::Underscore,
'`' => self.raw(),
'$' => self.math(),
- '-' => self.hyph(),
'=' => NodeKind::Eq,
c if c == '.' || c.is_ascii_digit() => self.numbering(start, c),
@@ -220,7 +222,7 @@ impl<'s> Tokens<'s> {
// Comments, parentheses, code.
'/' | '[' | ']' | '{' | '}' | '#' |
// Markup
- '~' | '*' | '_' | '`' | '$' | '-' | '\\'
+ '~' | '\'' | '"' | '*' | '_' | '`' | '$' | '-' | '\\'
};
loop {
@@ -269,8 +271,8 @@ impl<'s> Tokens<'s> {
// Parenthesis and hashtag.
'[' | ']' | '{' | '}' | '#' |
// Markup.
- '~' | '*' | '_' | '`' | '$' | '=' | '-' | '.' => {
- self.s.eat_assert(c);
+ '~' | '\'' | '"' | '*' | '_' | '`' | '$' | '=' | '-' | '.' => {
+ self.s.eat_assert(c) ;
NodeKind::Escape(c)
}
'u' if self.s.rest().starts_with("u{") => {
@@ -789,7 +791,7 @@ mod tests {
t!(Markup[" /"]: "hello-world" => Text("hello"), Minus, Text("world"));
// Test code symbols in text.
- t!(Markup[" /"]: "a():\"b" => Text("a():\"b"));
+ t!(Markup[" /"]: "a():\"b" => Text("a():"), Quote(true), Text("b"));
t!(Markup[" /"]: ";:,|/+" => Text(";:,|"), Text("/+"));
t!(Markup[" /"]: "=-a" => Eq, Minus, Text("a"));
t!(Markup[" "]: "#123" => Text("#"), Text("123"));
@@ -812,6 +814,8 @@ mod tests {
t!(Markup: r"\_" => Escape('_'));
t!(Markup: r"\=" => Escape('='));
t!(Markup: r"\~" => Escape('~'));
+ t!(Markup: r"\'" => Escape('\''));
+ t!(Markup: r#"\""# => Escape('"'));
t!(Markup: r"\`" => Escape('`'));
t!(Markup: r"\$" => Escape('$'));
t!(Markup: r"\#" => Escape('#'));
@@ -820,7 +824,6 @@ mod tests {
t!(Markup[" /"]: r"\a" => Text(r"\"), Text("a"));
t!(Markup[" /"]: r"\u" => Text(r"\"), Text("u"));
t!(Markup[" /"]: r"\1" => Text(r"\"), Text("1"));
- t!(Markup[" /"]: r#"\""# => Text(r"\"), Text("\""));
// Test basic unicode escapes.
t!(Markup: r"\u{}" => Error(Full, "invalid unicode escape sequence"));