XGDABCJNB4TBNPPDFFWXWU5NIEEDWB26GOETJMMEVEBWVCF2UWHAC
}
/// match on a string prefix, and bind the remainder to an identifier
// TODO allow prefix-binding-suffix and binding-suffix as well.
// No plans for infix strings, that would add ambiguity as well
// as complicating the parser.
// TODO Making this a TT muncher would simplify parsing and make it
// easier to make new cases
macro_rules! match_str {
(($name:ident) $($s:expr , $rem:ident => $body:expr ,)* _ => $else:expr) => {
$(if $name.starts_with($s) {
let $rem = &$name[$s.len()..];
$body
} else)* {$else}
};
// TODO make a macro that matches on e.g. `"pre":x => {}` and desugars to
// the kind of slice below
if line.starts_with("```") {
// ignore anything after the lead chars on preformat lines
return RawLine::Toggle {
alt: TextLine(&line[3..]),
};
} else if line.starts_with("=> ") {
let line = &line[3..];
match line.split_once(' ') {
Some((url, desc)) => {
let url = url.trim_start_matches(' ');
Line::Link {
url: TextLine(url),
description: Some(TextLine(desc)),
match_str! {(line)
"```", rem => {
// ignore anything after the lead chars on preformat lines
return RawLine::Toggle {
alt: TextLine(rem),
}
},
"=> ", rem => {
match rem.split_once(' ') {
Some((url, desc)) => {
let url = url.trim_start_matches(' ');
Line::Link {
url: TextLine(url),
description: Some(TextLine(desc)),
}
None => Line::Link {
url: TextLine(line),
description: None,
},
},
"* ", rem => {
Line::ListItem(TextLine(rem))
},
"# ", rem => {
Line::Heading {
level: 1,
title: TextLine(rem),
}
},
"## ", rem => {
Line::Heading {
level: 2,
title: TextLine(rem),
}
},
"### ", rem => {
Line::Heading {
level: 3,
title: TextLine(rem),
}
},
">", rem => {
Line::Quote(TextLine(rem))
},
_ => {
Line::Text(TextLine(line))
} else if line.starts_with("* ") {
Line::ListItem(TextLine(&line[2..]))
} else if line.starts_with("# ") {
Line::Heading {
level: 1,
title: TextLine(&line[2..]),
}
} else if line.starts_with("## ") {
Line::Heading {
level: 2,
title: TextLine(&line[3..]),
}
} else if line.starts_with("### ") {
Line::Heading {
level: 3,
title: TextLine(&line[4..]),
}
} else if line.starts_with(">") {
Line::Quote(TextLine(&line[1..]))
} else {
Line::Text(string)