Commit db9cb92737

db9cb9273704b0a5ff64c411043a4bf20296c77b

parent: d3b717d1be

Unregistered key

Ulyssa <git@ulyssa.dev> · 2024-03-24 03:06 UTC
committer: <noreply@github.com>

Enable autolinking when rendering Markdown (#226)

Layout: unified · split

src/message/mod.rs +28
@@ -129,6 +129,7 @@ const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);
129129
130130fn text_to_message_content(input: String) -> TextMessageEventContent {
131131 let mut options = ComrakOptions::default();
132 options.extension.autolink = true;
132133 options.extension.shortcodes = true;
133134 options.extension.strikethrough = true;
134135 options.render.hardbreaks = true;
@@ -1235,6 +1236,33 @@ pub mod tests {
12351236 assert_eq!(identity(&mc6), mc1);
12361237 }
12371238
1239 #[test]
1240 fn test_markdown_autolink() {
1241 let input = "http://example.com\n";
1242 let content = text_to_message_content(input.into());
1243 assert_eq!(content.body, input);
1244 assert_eq!(
1245 content.formatted.unwrap().body,
1246 "<p><a href=\"http://example.com\">http://example.com</a></p>\n"
1247 );
1248
1249 let input = "www.example.com\n";
1250 let content = text_to_message_content(input.into());
1251 assert_eq!(content.body, input);
1252 assert_eq!(
1253 content.formatted.unwrap().body,
1254 "<p><a href=\"http://www.example.com\">www.example.com</a></p>\n"
1255 );
1256
1257 let input = "See docs (they're at https://iamb.chat)\n";
1258 let content = text_to_message_content(input.into());
1259 assert_eq!(content.body, input);
1260 assert_eq!(
1261 content.formatted.unwrap().body,
1262 "<p>See docs (they're at <a href=\"https://iamb.chat\">https://iamb.chat</a>)</p>\n"
1263 );
1264 }
1265
12381266 #[test]
12391267 fn test_markdown_message() {
12401268 let input = "**bold**\n";