commit 560db69

default  ·  2024-10-25 05:13:28 +0000 UTC
parent 8de46e3
Accept any URL schema (not just http) in format_line().
1 files changed,  +24, -24
+24, -24
 1@@ -93,7 +93,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
 2             "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*"     "|"
 3             "!\\[[^]]+\\]\\([^\\)]+\\)"         "|"
 4             "\\[[^]]+\\]\\([^\\)]+\\)"          "|"
 5-            "https?:/" "/[^[:space:]]+"
 6+            "[a-z]+?:/" "/[^[:space:]]+"
 7         ")");
 8     int n = 0;
 9 
10@@ -133,29 +133,6 @@ static xs_str *format_line(const char *line, xs_list **attach)
11                 s = xs_str_cat(s, s2);
12             }
13             else
14-            if (xs_startswith(v, "http")) {
15-                xs *u  = xs_replace(v, "#", "#");
16-                xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
17-
18-                const char *mime = xs_mime_by_ext(v2);
19-
20-                if (attach != NULL && xs_startswith(mime, "image/")) {
21-                    /* if it's a link to an image, insert it as an attachment */
22-                    xs *d = xs_dict_new();
23-
24-                    d = xs_dict_append(d, "mediaType", mime);
25-                    d = xs_dict_append(d, "url",       v2);
26-                    d = xs_dict_append(d, "name",      "");
27-                    d = xs_dict_append(d, "type",      "Image");
28-
29-                    *attach = xs_list_append(*attach, d);
30-                }
31-                else {
32-                    xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
33-                    s = xs_str_cat(s, s1);
34-                }
35-            }
36-            else
37             if (*v == '[') {
38                 /* markdown-like links [label](url) */
39                 xs *w = xs_strip_chars_i(xs_replace(v, "#", "&#35;"), "[)");
40@@ -200,6 +177,29 @@ static xs_str *format_line(const char *line, xs_list **attach)
41                 else
42                     s = xs_str_cat(s, v);
43             }
44+            else
45+            if (xs_str_in(v, ":/" "/") != -1) {
46+                xs *u  = xs_replace(v, "#", "&#35;");
47+                xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
48+
49+                const char *mime = xs_mime_by_ext(v2);
50+
51+                if (attach != NULL && xs_startswith(mime, "image/")) {
52+                    /* if it's a link to an image, insert it as an attachment */
53+                    xs *d = xs_dict_new();
54+
55+                    d = xs_dict_append(d, "mediaType", mime);
56+                    d = xs_dict_append(d, "url",       v2);
57+                    d = xs_dict_append(d, "name",      "");
58+                    d = xs_dict_append(d, "type",      "Image");
59+
60+                    *attach = xs_list_append(*attach, d);
61+                }
62+                else {
63+                    xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
64+                    s = xs_str_cat(s, s1);
65+                }
66+            }
67             else
68                 s = xs_str_cat(s, v);
69         }