summaryrefslogtreecommitdiff
path: root/src/syntax/pretty.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-30 12:50:58 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-30 22:46:59 +0100
commit8d1ce390e21ce0a5812a4211c893ec359906d6f1 (patch)
tree5dbe1ad96af8ce8f9f01887340fe06025462e959 /src/syntax/pretty.rs
parentd7072f378fef733ae994fd9a1e767df4e4dd878e (diff)
Rework strong and emph
- Star and underscore not parsed as strong/emph inside of words - Stars/underscores must be balanced and they cannot go over paragraph break - New `strong` and `emph` classes
Diffstat (limited to 'src/syntax/pretty.rs')
-rw-r--r--src/syntax/pretty.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/syntax/pretty.rs b/src/syntax/pretty.rs
index e8110262..07ab979b 100644
--- a/src/syntax/pretty.rs
+++ b/src/syntax/pretty.rs
@@ -95,8 +95,8 @@ impl Pretty for MarkupNode {
Self::Space => p.push(' '),
Self::Linebreak => p.push_str(r"\"),
Self::Parbreak => p.push_str("\n\n"),
- Self::Strong => p.push('*'),
- Self::Emph => p.push('_'),
+ Self::Strong(strong) => strong.pretty(p),
+ Self::Emph(emph) => emph.pretty(p),
Self::Text(text) => p.push_str(text),
Self::Raw(raw) => raw.pretty(p),
Self::Math(math) => math.pretty(p),
@@ -113,6 +113,22 @@ impl Pretty for MarkupNode {
}
}
+impl Pretty for StrongNode {
+ fn pretty(&self, p: &mut Printer) {
+ p.push('*');
+ self.body().pretty(p);
+ p.push('*');
+ }
+}
+
+impl Pretty for EmphNode {
+ fn pretty(&self, p: &mut Printer) {
+ p.push('_');
+ self.body().pretty(p);
+ p.push('_');
+ }
+}
+
impl Pretty for RawNode {
fn pretty(&self, p: &mut Printer) {
// Find out how many backticks we need.
@@ -604,12 +620,12 @@ mod tests {
#[test]
fn test_pretty_print_markup() {
// Basic stuff.
- roundtrip("*");
- roundtrip("_");
roundtrip(" ");
+ roundtrip("*ab*");
roundtrip("\\ ");
roundtrip("\n\n");
roundtrip("hi");
+ roundtrip("_ab_");
roundtrip("= *Ok*");
roundtrip("- Ok");