summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f5a1207..e75221c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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("![") {
- if let Some((line, "")) = line.rsplit_once(")") {
- let parts: Vec<&str> = line.split("](").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;
}
+