summaryrefslogtreecommitdiff
path: root/src/line.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-03-14 12:55:00 +1300
committerBen Bridle <ben@derelict.engineering>2025-03-14 12:55:00 +1300
commit01d6fb5a1f79ff1ef48cc69b42d8a91ef9a6d2f1 (patch)
tree410b7f28420be833dbcb57cbdb93c01ce6ad300f /src/line.rs
parent883a2a63023ea9b1e4b2bb51831ea1dafcb7346a (diff)
downloadmarkdown-01d6fb5a1f79ff1ef48cc69b42d8a91ef9a6d2f1.zip
Add optional labels to internal links
Internal links can have labels in the same manner as with external links, by separating the label and path from each other with a :: token.
Diffstat (limited to 'src/line.rs')
-rw-r--r--src/line.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/line.rs b/src/line.rs
index b60b55c..5ef940f 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -81,6 +81,15 @@ impl ToString for Line {
}
}
+fn internal_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::InternalLink { label, path } )
+ } else {
+ Some( Token::InternalLink { label: String::new(), path: inside })
+ }
+}
fn external_link(inside: String) -> Option<Token> {
if let Some((label, path)) = inside.split_once("::") {
@@ -101,7 +110,7 @@ const DELIMITERS: [(fn(String)->Option<Token>, &str, &str, &str); 6] = [
( make!(Token::Italic), "_", "_", "_" ),
( make!(Token::Monospace), "`", "`", "`" ),
( make!(Token::Math), "$", "$", "$" ),
- ( make!(Token::InternalLink), "{", "}", "{}" ),
+ ( internal_link, "{", "}", "{}" ),
( external_link, "<", ">", "<>" ),
];