diff options
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | format.c | 29 | ||||
| -rw-r--r-- | html.c | 4 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | mastoapi.c | 2 | ||||
| -rw-r--r-- | snac.h | 2 |
6 files changed, 34 insertions, 9 deletions
diff --git a/activitypub.c b/activitypub.c index 3806353..df78854 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1190,7 +1190,7 @@ xs_dict *msg_actor(snac *snac) | |||
| 1190 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); | 1190 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); |
| 1191 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); | 1191 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); |
| 1192 | 1192 | ||
| 1193 | xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL); | 1193 | xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL, NULL); |
| 1194 | f_bio = process_tags(snac, f_bio_2, &tags); | 1194 | f_bio = process_tags(snac, f_bio_2, &tags); |
| 1195 | msg = xs_dict_set(msg, "summary", f_bio); | 1195 | msg = xs_dict_set(msg, "summary", f_bio); |
| 1196 | msg = xs_dict_set(msg, "tag", tags); | 1196 | msg = xs_dict_set(msg, "tag", tags); |
| @@ -1398,7 +1398,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 1398 | } | 1398 | } |
| 1399 | 1399 | ||
| 1400 | /* format the content */ | 1400 | /* format the content */ |
| 1401 | fc2 = not_really_markdown(content, &atls); | 1401 | fc2 = not_really_markdown(content, &atls, &tag); |
| 1402 | 1402 | ||
| 1403 | if (in_reply_to != NULL && *in_reply_to) { | 1403 | if (in_reply_to != NULL && *in_reply_to) { |
| 1404 | xs *p_msg = NULL; | 1404 | xs *p_msg = NULL; |
| @@ -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 | ||
| @@ -775,7 +775,7 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 775 | 775 | ||
| 776 | if (read_only) { | 776 | if (read_only) { |
| 777 | xs *es1 = encode_html(xs_dict_get(user->config, "bio")); | 777 | xs *es1 = encode_html(xs_dict_get(user->config, "bio")); |
| 778 | xs *bio1 = not_really_markdown(es1, NULL); | 778 | xs *bio1 = not_really_markdown(es1, NULL, NULL); |
| 779 | xs *tags = xs_list_new(); | 779 | xs *tags = xs_list_new(); |
| 780 | xs *bio2 = process_tags(user, bio1, &tags); | 780 | xs *bio2 = process_tags(user, bio1, &tags); |
| 781 | 781 | ||
| @@ -2657,7 +2657,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2657 | return 403; | 2657 | return 403; |
| 2658 | 2658 | ||
| 2659 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); | 2659 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); |
| 2660 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); | 2660 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL, NULL); |
| 2661 | 2661 | ||
| 2662 | xs *rss_title = xs_fmt("%s (@%s@%s)", | 2662 | xs *rss_title = xs_fmt("%s (@%s@%s)", |
| 2663 | xs_dict_get(snac.config, "name"), | 2663 | xs_dict_get(snac.config, "name"), |
| @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) | |||
| 98 | if (strcmp(cmd, "markdown") == 0) { /** **/ | 98 | if (strcmp(cmd, "markdown") == 0) { /** **/ |
| 99 | /* undocumented, for testing only */ | 99 | /* undocumented, for testing only */ |
| 100 | xs *c = xs_readall(stdin); | 100 | xs *c = xs_readall(stdin); |
| 101 | xs *fc = not_really_markdown(c, NULL); | 101 | xs *fc = not_really_markdown(c, NULL, NULL); |
| 102 | 102 | ||
| 103 | printf("<html>\n%s\n</html>\n", fc); | 103 | printf("<html>\n%s\n</html>\n", fc); |
| 104 | return 0; | 104 | return 0; |
| @@ -2717,7 +2717,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, | |||
| 2717 | if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) { | 2717 | if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) { |
| 2718 | const char *content = xs_dict_get(args, "status"); | 2718 | const char *content = xs_dict_get(args, "status"); |
| 2719 | xs *atls = xs_list_new(); | 2719 | xs *atls = xs_list_new(); |
| 2720 | xs *f_content = not_really_markdown(content, &atls); | 2720 | xs *f_content = not_really_markdown(content, &atls, NULL); |
| 2721 | 2721 | ||
| 2722 | /* replace fields with new content */ | 2722 | /* replace fields with new content */ |
| 2723 | msg = xs_dict_set(msg, "sourceContent", content); | 2723 | msg = xs_dict_set(msg, "sourceContent", content); |
| @@ -305,7 +305,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, | |||
| 305 | char **body, int *b_size, char **ctype); | 305 | char **body, int *b_size, char **ctype); |
| 306 | 306 | ||
| 307 | xs_dict *emojis(void); | 307 | xs_dict *emojis(void); |
| 308 | xs_str *not_really_markdown(const char *content, xs_list **attach); | 308 | xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag); |
| 309 | xs_str *sanitize(const char *content); | 309 | xs_str *sanitize(const char *content); |
| 310 | xs_str *encode_html(const char *str); | 310 | xs_str *encode_html(const char *str); |
| 311 | 311 | ||