diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index 78cf667..28802e2 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -134,16 +134,21 @@ pub fn markdown_to_html(text: &str) -> Result { let mut borrowed_node = node.data.borrow_mut(); *borrowed_node = Ast::new(NodeValue::Paragraph); }, - NodeValue::Link(link) => { + NodeValue::Link(_) => { if let Some(prev) = node.previous_sibling() { if let NodeValue::Text(ref prev_text) = prev.data.borrow().value { let prev_text = String::from_utf8(prev_text.to_vec())?; - // Remove autolink if object link syntax is found - if prev_text.ends_with("[[") { + // Remove autolink if mention or object link syntax is found + if prev_text.ends_with('@') || prev_text.ends_with("[[") { + let mut link_text = vec![]; for child in node.children() { child.detach(); + let child_value = &child.data.borrow().value; + if let NodeValue::Text(child_text) = child_value { + link_text.extend(child_text); + }; }; - let text = NodeValue::Text(link.url); + let text = NodeValue::Text(link_text); let mut borrowed_node = node.data.borrow_mut(); *borrowed_node = Ast::new(text); }; @@ -181,4 +186,25 @@ mod tests { ); assert_eq!(html, expected_html); } + + #[test] + fn test_markdown_to_html_mention() { + let text = "@user@example.org test"; + let html = markdown_to_html(text).unwrap(); + assert_eq!(html, format!("

{}

", text)); + } + + #[test] + fn test_markdown_to_html_hashtag() { + let text = "#hashtag test"; + let html = markdown_to_html(text).unwrap(); + assert_eq!(html, format!("

{}

", text)); + } + + #[test] + fn test_markdown_to_html_object_link() { + let text = "[[https://example.org/objects/1]] test"; + let html = markdown_to_html(text).unwrap(); + assert_eq!(html, format!("

{}

", text)); + } }