summaryrefslogtreecommitdiff
path: root/src/syntax/node.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-11 17:33:13 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-11 17:33:13 +0100
commit1711b67877ce5c290e049775c340c9324f15341e (patch)
tree92d6ff7285cdc2d694ccfdf733ce8757866636ec /src/syntax/node.rs
parentf9197dcfef11c4c054a460c80ff6023dae6f1f2a (diff)
Move all pretty printing into one module and pretty print values 🦋
Diffstat (limited to 'src/syntax/node.rs')
-rw-r--r--src/syntax/node.rs92
1 files changed, 0 insertions, 92 deletions
diff --git a/src/syntax/node.rs b/src/syntax/node.rs
index 246790f6..19fdfa50 100644
--- a/src/syntax/node.rs
+++ b/src/syntax/node.rs
@@ -23,30 +23,6 @@ pub enum Node {
Expr(Expr),
}
-impl Pretty for Node {
- fn pretty(&self, p: &mut Printer) {
- match self {
- Self::Strong => p.push('*'),
- Self::Emph => p.push('_'),
- Self::Space => p.push(' '),
- Self::Linebreak => p.push_str(r"\"),
- Self::Parbreak => p.push_str("\n\n"),
- // TODO: Handle escaping.
- Self::Text(text) => p.push_str(&text),
- Self::Heading(heading) => heading.pretty(p),
- Self::Raw(raw) => raw.pretty(p),
- Self::Expr(expr) => {
- if let Expr::Call(call) = expr {
- // Format function templates appropriately.
- call.pretty_bracketed(p, false)
- } else {
- expr.pretty(p);
- }
- }
- }
- }
-}
-
/// A section heading: `= Introduction`.
#[derive(Debug, Clone, PartialEq)]
pub struct NodeHeading {
@@ -56,15 +32,6 @@ pub struct NodeHeading {
pub contents: Tree,
}
-impl Pretty for NodeHeading {
- fn pretty(&self, p: &mut Printer) {
- for _ in 0 ..= self.level {
- p.push('=');
- }
- self.contents.pretty(p);
- }
-}
-
/// A raw block with optional syntax highlighting: `` `raw` ``.
///
/// Raw blocks start with 1 or 3+ backticks and end with the same number of
@@ -139,62 +106,3 @@ pub struct NodeRaw {
/// and contains at least one newline.
pub block: bool,
}
-
-impl Pretty for NodeRaw {
- fn pretty(&self, p: &mut Printer) {
- // Find out how many backticks we need.
- let mut backticks = 1;
-
- // Language tag and block-level are only possible with 3+ backticks.
- if self.lang.is_some() || self.block {
- backticks = 3;
- }
-
- // More backticks may be required if there are lots of consecutive
- // backticks in the lines.
- let mut count;
- for line in &self.lines {
- count = 0;
- for c in line.chars() {
- if c == '`' {
- count += 1;
- backticks = backticks.max(3).max(count + 1);
- } else {
- count = 0;
- }
- }
- }
-
- // Starting backticks.
- for _ in 0 .. backticks {
- p.push('`');
- }
-
- // Language tag.
- if let Some(lang) = &self.lang {
- lang.pretty(p);
- }
-
- // Start untrimming.
- if self.block {
- p.push('\n');
- } else if backticks >= 3 {
- p.push(' ');
- }
-
- // The lines.
- p.join(&self.lines, "\n", |line, p| p.push_str(line));
-
- // End untrimming.
- if self.block {
- p.push('\n');
- } else if self.lines.last().map_or(false, |line| line.trim_end().ends_with('`')) {
- p.push(' ');
- }
-
- // Ending backticks.
- for _ in 0 .. backticks {
- p.push('`');
- }
- }
-}