diff options
| author | 2025-05-03 18:55:10 +0200 | |
|---|---|---|
| committer | 2025-05-03 18:55:10 +0200 | |
| commit | 6878e3fc939c3dac9853a3a33bfab7a289c7648b (patch) | |
| tree | a1e68fec08620a42a42c9a68edfdd80b4213497e /format.c | |
| parent | No longer drop text/html attachements. (diff) | |
| download | snac2-6878e3fc939c3dac9853a3a33bfab7a289c7648b.tar.gz snac2-6878e3fc939c3dac9853a3a33bfab7a289c7648b.tar.xz snac2-6878e3fc939c3dac9853a3a33bfab7a289c7648b.zip | |
Also add direct and markdown links in posts as attachments.
Diffstat (limited to 'format.c')
| -rw-r--r-- | format.c | 27 |
1 files changed, 25 insertions, 2 deletions
| @@ -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, "#", "#"), "@", "@"); | 224 | xs *u = xs_replace_i(xs_replace(v, "#", "#"), "@", "@"); |
| 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 |