summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'format.c')
-rw-r--r--format.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/format.c b/format.c
index 3089955..862d766 100644
--- a/format.c
+++ b/format.c
@@ -154,10 +154,22 @@ static xs_str *format_line(const char *line, xs_list **attach)
154 xs *l = xs_split_n(w, "](", 1); 154 xs *l = xs_split_n(w, "](", 1);
155 155
156 if (xs_list_len(l) == 2) { 156 if (xs_list_len(l) == 2) {
157 xs *link = xs_fmt("<a href=\"%s\">%s</a>", 157 const char *name = xs_list_get(l, 0);
158 xs_list_get(l, 1), xs_list_get(l, 0)); 158 const char *url = xs_list_get(l, 1);
159
160 xs *link = xs_fmt("<a href=\"%s\">%s</a>", url, name);
159 161
160 s = xs_str_cat(s, link); 162 s = xs_str_cat(s, link);
163
164 /* also add the link as an attachment */
165 xs *d = xs_dict_new();
166
167 d = xs_dict_append(d, "mediaType", "text/html");
168 d = xs_dict_append(d, "url", url);
169 d = xs_dict_append(d, "name", name);
170 d = xs_dict_append(d, "type", "Link");
171
172 *attach = xs_list_append(*attach, d);
161 } 173 }
162 else 174 else
163 s = xs_str_cat(s, v); 175 s = xs_str_cat(s, v);
@@ -208,6 +220,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
208 } 220 }
209 else 221 else
210 if (xs_str_in(v, ":/" "/") != -1) { 222 if (xs_str_in(v, ":/" "/") != -1) {
223 /* direct URLs in the post body */
211 xs *u = xs_replace_i(xs_replace(v, "#", "&#35;"), "@", "&#64;"); 224 xs *u = xs_replace_i(xs_replace(v, "#", "&#35;"), "@", "&#64;");
212 225
213 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)"); 226 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
@@ -240,6 +253,16 @@ static xs_str *format_line(const char *line, xs_list **attach)
240 else { 253 else {
241 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u); 254 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
242 s = xs_str_cat(s, s1); 255 s = xs_str_cat(s, s1);
256
257 /* also add the link as an attachment */
258 xs *d = xs_dict_new();
259
260 d = xs_dict_append(d, "mediaType", "text/html");
261 d = xs_dict_append(d, "url", v2);
262 d = xs_dict_append(d, "name", "");
263 d = xs_dict_append(d, "type", "Link");
264
265 *attach = xs_list_append(*attach, d);
243 } 266 }
244 } 267 }
245 else 268 else