summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/format.c b/format.c
index 573b702..9a3ef87 100644
--- a/format.c
+++ b/format.c
@@ -93,7 +93,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
93 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" 93 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|"
94 "!\\[[^]]+\\]\\([^\\)]+\\)" "|" 94 "!\\[[^]]+\\]\\([^\\)]+\\)" "|"
95 "\\[[^]]+\\]\\([^\\)]+\\)" "|" 95 "\\[[^]]+\\]\\([^\\)]+\\)" "|"
96 "https?:/" "/[^[:space:]]+" 96 "[a-z]+?:/" "/[^[:space:]]+"
97 ")"); 97 ")");
98 int n = 0; 98 int n = 0;
99 99
@@ -133,29 +133,6 @@ static xs_str *format_line(const char *line, xs_list **attach)
133 s = xs_str_cat(s, s2); 133 s = xs_str_cat(s, s2);
134 } 134 }
135 else 135 else
136 if (xs_startswith(v, "http")) {
137 xs *u = xs_replace(v, "#", "#");
138 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
139
140 const char *mime = xs_mime_by_ext(v2);
141
142 if (attach != NULL && xs_startswith(mime, "image/")) {
143 /* if it's a link to an image, insert it as an attachment */
144 xs *d = xs_dict_new();
145
146 d = xs_dict_append(d, "mediaType", mime);
147 d = xs_dict_append(d, "url", v2);
148 d = xs_dict_append(d, "name", "");
149 d = xs_dict_append(d, "type", "Image");
150
151 *attach = xs_list_append(*attach, d);
152 }
153 else {
154 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
155 s = xs_str_cat(s, s1);
156 }
157 }
158 else
159 if (*v == '[') { 136 if (*v == '[') {
160 /* markdown-like links [label](url) */ 137 /* markdown-like links [label](url) */
161 xs *w = xs_strip_chars_i(xs_replace(v, "#", "&#35;"), "[)"); 138 xs *w = xs_strip_chars_i(xs_replace(v, "#", "&#35;"), "[)");
@@ -201,6 +178,29 @@ static xs_str *format_line(const char *line, xs_list **attach)
201 s = xs_str_cat(s, v); 178 s = xs_str_cat(s, v);
202 } 179 }
203 else 180 else
181 if (xs_str_in(v, ":/" "/") != -1) {
182 xs *u = xs_replace(v, "#", "&#35;");
183 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
184
185 const char *mime = xs_mime_by_ext(v2);
186
187 if (attach != NULL && xs_startswith(mime, "image/")) {
188 /* if it's a link to an image, insert it as an attachment */
189 xs *d = xs_dict_new();
190
191 d = xs_dict_append(d, "mediaType", mime);
192 d = xs_dict_append(d, "url", v2);
193 d = xs_dict_append(d, "name", "");
194 d = xs_dict_append(d, "type", "Image");
195
196 *attach = xs_list_append(*attach, d);
197 }
198 else {
199 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
200 s = xs_str_cat(s, s1);
201 }
202 }
203 else
204 s = xs_str_cat(s, v); 204 s = xs_str_cat(s, v);
205 } 205 }
206 else 206 else