Skip to content

Commit

Permalink
Enable autolinking when rendering Markdown (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa committed Mar 24, 2024
1 parent d3b717d commit db9cb92
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);

fn text_to_message_content(input: String) -> TextMessageEventContent {
let mut options = ComrakOptions::default();
options.extension.autolink = true;
options.extension.shortcodes = true;
options.extension.strikethrough = true;
options.render.hardbreaks = true;
Expand Down Expand Up @@ -1235,6 +1236,33 @@ pub mod tests {
assert_eq!(identity(&mc6), mc1);
}

#[test]
fn test_markdown_autolink() {
let input = "http://example.com\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(
content.formatted.unwrap().body,
"<p><a href=\"http://example.com\">http://example.com</a></p>\n"
);

let input = "www.example.com\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(
content.formatted.unwrap().body,
"<p><a href=\"http://www.example.com\">www.example.com</a></p>\n"
);

let input = "See docs (they're at https://iamb.chat)\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(
content.formatted.unwrap().body,
"<p>See docs (they're at <a href=\"https://iamb.chat\">https://iamb.chat</a>)</p>\n"
);
}

#[test]
fn test_markdown_message() {
let input = "**bold**\n";
Expand Down

0 comments on commit db9cb92

Please sign in to comment.