diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-01-19 18:49:36 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-01-19 18:51:10 +1300 |
commit | d0ff550b264206109349f0385c145f340ddf992b (patch) | |
tree | d7ffcb3f22bf5698ae00756b96c532db62de8bd6 /src/line.rs | |
parent | 5c9ff7c79fec508017ea6c15b2612bc99276a9b6 (diff) | |
download | markdown-d0ff550b264206109349f0385c145f340ddf992b.zip |
Change syntax
Internal links are now delimited with braces, and external links are
now delimited with angle brackets. A label is separated from a path in
an external link with two consecutive colons.
Embed blocks are now delimited with angle brackets in the same manner
as external links, with label separated from path with two consecutive
colons. Embed blocks still begin with a single exclamation mark.
Bold line elements are now delimited with only a single * character,
instead of two. This is to match the other delimiters, which each use
only a single character.
Diffstat (limited to 'src/line.rs')
-rw-r--r-- | src/line.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/line.rs b/src/line.rs index fce628c..b60b55c 100644 --- a/src/line.rs +++ b/src/line.rs @@ -82,31 +82,27 @@ impl ToString for Line { } -fn unlabeled_extern_link(path: String) -> Option<Token> { - Some( Token::ExternalLink { path, label:String::new() } ) -} - -fn labelled_extern_link(s: String) -> Option<Token> { - let (label, path) = match s.split_once("](") { - Some((l, t)) => (l.to_string(), t.to_string()), - None => return None, - }; - if label.contains("]") || path.contains("]") { return None } - Some( Token::ExternalLink { label, path } ) +fn external_link(inside: String) -> Option<Token> { + if let Some((label, path)) = inside.split_once("::") { + let label = label.trim().to_string(); + let path = path.trim().to_string(); + Some( Token::ExternalLink { label, path } ) + } else { + Some( Token::ExternalLink { label: String::new(), path: inside }) + } } -macro_rules! con { +macro_rules! make { ($v:expr) => {|s| Some($v(s)) }; } -const DELIMITERS: [(fn(String)->Option<Token>, &str, &str, &str); 7] = [ - ( con!(Token::Bold), "**", "**", "*" ), - ( con!(Token::Italic), "_", "_", "_" ), - ( con!(Token::Monospace), "`", "`", "`" ), - ( con!(Token::Math), "$", "$", "$" ), - ( con!(Token::InternalLink), "[[", "]]", "[]" ), - ( labelled_extern_link, "[", ")", "[]()" ), - ( unlabeled_extern_link, "<", ">", "<>" ), +const DELIMITERS: [(fn(String)->Option<Token>, &str, &str, &str); 6] = [ + ( make!(Token::Bold), "*", "*", "*" ), + ( make!(Token::Italic), "_", "_", "_" ), + ( make!(Token::Monospace), "`", "`", "`" ), + ( make!(Token::Math), "$", "$", "$" ), + ( make!(Token::InternalLink), "{", "}", "{}" ), + ( external_link, "<", ">", "<>" ), ]; fn is_whitespace(c: &char) -> bool { |