diff options
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; } + |