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/lib.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/lib.rs')
-rw-r--r-- | src/lib.rs | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -108,8 +108,8 @@ impl MarkdownDocument { Block::Heading { level, line: Line::from_str(&line) }), BlockLine::Break => blocks.push(Block::Break), BlockLine::BlankLine => (), - BlockLine::Paragraph(line) => match parse_embedded(&line) { - Some(embedded) => blocks.push(embedded), + BlockLine::Paragraph(line) => match parse_embed(&line) { + Some(embed) => blocks.push(embed), None => blocks.push(Block::Paragraph(Line::from_str(&line))), } } @@ -139,24 +139,21 @@ enum BlockMultiline<'a> { Fragment { language: &'a str, content: Vec<&'a str> }, } -fn parse_embedded(line: &str) -> Option<Block> { +fn parse_embed(line: &str) -> Option<Block> { let line = line.trim(); - if let Some(("", line)) = line.split_once(".collect(); - if parts.len() == 2 { - let label = parts[0].to_string(); - let path = parts[1].to_string(); - return Some(Block::Embedded { label, path }) + if let Some(stripped) = line.strip_prefix("!<") { + if let Some(stripped) = stripped.strip_suffix(">") { + if let Some((label, path)) = stripped.split_once("::") { + let label = label.trim().to_string(); + let path = path.trim().to_string(); + return Some(Block::Embed { label, path }) + } else { + let label = String::new(); + let path = stripped.trim().to_string(); + return Some(Block::Embed { label, path }) } } } - if let Some(("", line)) = line.split_once("![[") { - if let Some((line, "")) = line.rsplit_once("]]") { - let label = line.to_string(); - let path = line.to_string(); - return Some(Block::Embedded { label, path }) - } - } return None; } + |