diff --git a/src/frontend/markdown.rs b/src/frontend/markdown.rs index adc995b..372e5bb 100644 --- a/src/frontend/markdown.rs +++ b/src/frontend/markdown.rs @@ -81,6 +81,7 @@ fn markdown_parser() -> MarkdownIt { #[derive(Debug)] pub struct ArticleLink { + label: String, title: String, domain: String, } @@ -94,7 +95,7 @@ impl NodeValue for ArticleLink { attrs.push(("href", link)); fmt.open("a", &attrs); - fmt.text(&self.title); + fmt.text(&self.label); fmt.close("a"); } } @@ -117,7 +118,10 @@ impl InlineRule for ArticleLinkScanner { let i = start + length - SEPARATOR_LENGTH; let content = &state.src[start..i]; content.split_once('@').map(|(title, domain)| { + // Handle custom link label if provided, otherwise use title as label + let (domain, label) = domain.split_once('|').unwrap_or((&domain, &title)); let node = Node::new(ArticleLink { + label: label.to_string(), title: title.to_string(), domain: domain.to_string(), }); @@ -180,12 +184,18 @@ impl InlineRule for MathEquationScanner { #[test] fn test_markdown_article_link() { let parser = markdown_parser(); - let rendered = parser - .parse("some text [[Title@example.com]] and more") + let plain = parser.parse("[[Title@example.com]]").render(); + assert_eq!( + "
\n", + plain + ); + + let with_label = parser + .parse("[[Title@example.com|Example Article]]") .render(); assert_eq!( - "some text Title and more
\n", - rendered + "\n", + with_label ); }