commit 2384a54

default  ·  2024-12-26 02:55:27 +0000 UTC
parent ea0c128
Make xmpp and mailto URLs clickable.
2 files changed,  +13, -2
M html.c
+12, -1
 1@@ -7,6 +7,7 @@
 2 #include "xs_html.h"
 3 #include "xs_json.h"
 4 #include "xs_time.h"
 5+#include "xs_match.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -93,7 +94,8 @@ static xs_str *format_line(const char *line, xs_list **attach)
10             "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*"     "|"
11             "!\\[[^]]+\\]\\([^\\)]+\\)"         "|"
12             "\\[[^]]+\\]\\([^\\)]+\\)"          "|"
13-            "[a-z]+:/" "/[^[:space:]]+"
14+            "[a-z]+:/" "/[^[:space:]]+"         "|"
15+            "(mailto|xmpp):[^@[:space:]]+@[^[:space:]]+"
16         ")");
17     int n = 0;
18 
19@@ -229,6 +231,15 @@ static xs_str *format_line(const char *line, xs_list **attach)
20                     s = xs_str_cat(s, s1);
21                 }
22             }
23+            else
24+            if (xs_match(v, "mailto*|xmpp*")) {
25+                xs *u  = xs_replace_i(xs_replace(v, "#", "#"), "@", "@");
26+
27+                xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
28+
29+                xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
30+                s = xs_str_cat(s, s1);
31+            }
32             else
33                 s = xs_str_cat(s, v);
34         }
M html.c
+1, -1
1@@ -934,7 +934,7 @@ static xs_html *html_user_body(snac *user, int read_only)
2                     }
3                 }
4                 else
5-                if (xs_startswith(v, "gemini:/")) {
6+                if (xs_startswith(v, "gemini:/") || xs_startswith(v, "xmpp:")) {
7                     value = xs_html_tag("a",
8                         xs_html_attr("rel", "me"),
9                         xs_html_attr("href", v),