diff options
| author | 2024-03-25 16:15:09 +0100 | |
|---|---|---|
| committer | 2024-03-25 16:15:09 +0100 | |
| commit | adf0a13992edb85738ac983a872937a805629474 (patch) | |
| tree | 31e084c9ff92a82e2083e8225e703bceeec56981 /format.c | |
| parent | Emojis are now read from ~/emojis.json. (diff) | |
| download | penes-snac2-adf0a13992edb85738ac983a872937a805629474.tar.gz penes-snac2-adf0a13992edb85738ac983a872937a805629474.tar.xz penes-snac2-adf0a13992edb85738ac983a872937a805629474.zip | |
If an emoji in emojis.json is an URL to an image, it's stored in the tag list.
Diffstat (limited to 'format.c')
| -rw-r--r-- | format.c | 29 |
1 files changed, 27 insertions, 2 deletions
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "xs_mime.h" | 6 | #include "xs_mime.h" |
| 7 | #include "xs_html.h" | 7 | #include "xs_html.h" |
| 8 | #include "xs_json.h" | 8 | #include "xs_json.h" |
| 9 | #include "xs_time.h" | ||
| 9 | 10 | ||
| 10 | #include "snac.h" | 11 | #include "snac.h" |
| 11 | 12 | ||
| @@ -140,7 +141,7 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | 143 | ||
| 143 | xs_str *not_really_markdown(const char *content, xs_list **attach) | 144 | xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag) |
| 144 | /* formats a content using some Markdown rules */ | 145 | /* formats a content using some Markdown rules */ |
| 145 | { | 146 | { |
| 146 | xs_str *s = xs_str_new(NULL); | 147 | xs_str *s = xs_str_new(NULL); |
| @@ -229,7 +230,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach) | |||
| 229 | char *k, *v; | 230 | char *k, *v; |
| 230 | 231 | ||
| 231 | while (xs_dict_next(d, &k, &v, &c)) { | 232 | while (xs_dict_next(d, &k, &v, &c)) { |
| 232 | s = xs_replace_i(s, k, v); | 233 | const char *t = NULL; |
| 234 | |||
| 235 | /* is it an URL to an image? */ | ||
| 236 | if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) { | ||
| 237 | if (tag) { | ||
| 238 | /* add the emoji to the tag list */ | ||
| 239 | xs *e = xs_dict_new(); | ||
| 240 | xs *i = xs_dict_new(); | ||
| 241 | xs *u = xs_str_utctime(0, ISO_DATE_SPEC); | ||
| 242 | |||
| 243 | e = xs_dict_append(e, "id", v); | ||
| 244 | e = xs_dict_append(e, "type", "Emoji"); | ||
| 245 | e = xs_dict_append(e, "name", k); | ||
| 246 | e = xs_dict_append(e, "updated", u); | ||
| 247 | |||
| 248 | i = xs_dict_append(i, "type", "Image"); | ||
| 249 | i = xs_dict_append(i, "mediaType", t); | ||
| 250 | i = xs_dict_append(i, "url", v); | ||
| 251 | e = xs_dict_append(e, "icon", i); | ||
| 252 | |||
| 253 | *tag = xs_list_append(*tag, e); | ||
| 254 | } | ||
| 255 | } | ||
| 256 | else | ||
| 257 | s = xs_replace_i(s, k, v); | ||
| 233 | } | 258 | } |
| 234 | } | 259 | } |
| 235 | 260 | ||