diff options
| author | 2023-05-21 20:32:23 +0200 | |
|---|---|---|
| committer | 2023-05-21 20:32:23 +0200 | |
| commit | 49362f54049a357e52cd6c57d2aa20d33add3307 (patch) | |
| tree | 0417bac6b8157ce7be07be86b7eb6915bb24cdf7 | |
| parent | Updated TODO. (diff) | |
| download | penes-snac2-49362f54049a357e52cd6c57d2aa20d33add3307.tar.gz penes-snac2-49362f54049a357e52cd6c57d2aa20d33add3307.tar.xz penes-snac2-49362f54049a357e52cd6c57d2aa20d33add3307.zip | |
Convert image links in notes to attachments.
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | format.c | 27 | ||||
| -rw-r--r-- | html.c | 4 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | snac.h | 2 |
5 files changed, 28 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c index 18ed25c..406aee8 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -646,7 +646,7 @@ d_char *msg_actor(snac *snac) | |||
| 646 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); | 646 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); |
| 647 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); | 647 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); |
| 648 | 648 | ||
| 649 | f_bio = not_really_markdown(xs_dict_get(snac->config, "bio")); | 649 | f_bio = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL); |
| 650 | msg = xs_dict_set(msg, "summary", f_bio); | 650 | msg = xs_dict_set(msg, "summary", f_bio); |
| 651 | 651 | ||
| 652 | char *folders[] = { "inbox", "outbox", "followers", "following", NULL }; | 652 | char *folders[] = { "inbox", "outbox", "followers", "following", NULL }; |
| @@ -789,7 +789,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | /* format the content */ | 791 | /* format the content */ |
| 792 | fc2 = not_really_markdown(content); | 792 | fc2 = not_really_markdown(content, &atls); |
| 793 | 793 | ||
| 794 | if (in_reply_to != NULL && *in_reply_to) { | 794 | if (in_reply_to != NULL && *in_reply_to) { |
| 795 | xs *p_msg = NULL; | 795 | xs *p_msg = NULL; |
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_regex.h" | 5 | #include "xs_regex.h" |
| 6 | #include "xs_mime.h" | ||
| 6 | 7 | ||
| 7 | #include "snac.h" | 8 | #include "snac.h" |
| 8 | 9 | ||
| @@ -38,7 +39,7 @@ struct { | |||
| 38 | }; | 39 | }; |
| 39 | 40 | ||
| 40 | 41 | ||
| 41 | static xs_str *format_line(const char *line) | 42 | static xs_str *format_line(const char *line, xs_list **attach) |
| 42 | /* formats a line */ | 43 | /* formats a line */ |
| 43 | { | 44 | { |
| 44 | xs_str *s = xs_str_new(NULL); | 45 | xs_str *s = xs_str_new(NULL); |
| @@ -73,8 +74,24 @@ static xs_str *format_line(const char *line) | |||
| 73 | else | 74 | else |
| 74 | if (xs_startswith(v, "http")) { | 75 | if (xs_startswith(v, "http")) { |
| 75 | xs *v2 = xs_strip_chars_i(xs_dup(v), "."); | 76 | xs *v2 = xs_strip_chars_i(xs_dup(v), "."); |
| 76 | xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, v); | 77 | |
| 77 | s = xs_str_cat(s, s1); | 78 | const char *mime = xs_mime_by_ext(v2); |
| 79 | |||
| 80 | if (attach != NULL && xs_startswith(mime, "image/")) { | ||
| 81 | /* if it's a link to an image, insert it as an attachment */ | ||
| 82 | xs *d = xs_dict_new(); | ||
| 83 | |||
| 84 | d = xs_dict_append(d, "mediaType", mime); | ||
| 85 | d = xs_dict_append(d, "url", v2); | ||
| 86 | d = xs_dict_append(d, "name", ""); | ||
| 87 | d = xs_dict_append(d, "type", "Image"); | ||
| 88 | |||
| 89 | *attach = xs_list_append(*attach, d); | ||
| 90 | } | ||
| 91 | else { | ||
| 92 | xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, v); | ||
| 93 | s = xs_str_cat(s, s1); | ||
| 94 | } | ||
| 78 | } | 95 | } |
| 79 | else | 96 | else |
| 80 | s = xs_str_cat(s, v); | 97 | s = xs_str_cat(s, v); |
| @@ -90,7 +107,7 @@ static xs_str *format_line(const char *line) | |||
| 90 | } | 107 | } |
| 91 | 108 | ||
| 92 | 109 | ||
| 93 | xs_str *not_really_markdown(const char *content) | 110 | xs_str *not_really_markdown(const char *content, xs_list **attach) |
| 94 | /* formats a content using some Markdown rules */ | 111 | /* formats a content using some Markdown rules */ |
| 95 | { | 112 | { |
| 96 | xs_str *s = xs_str_new(NULL); | 113 | xs_str *s = xs_str_new(NULL); |
| @@ -119,7 +136,7 @@ xs_str *not_really_markdown(const char *content) | |||
| 119 | if (in_pre) | 136 | if (in_pre) |
| 120 | ss = xs_dup(v); | 137 | ss = xs_dup(v); |
| 121 | else | 138 | else |
| 122 | ss = xs_strip_i(format_line(v)); | 139 | ss = xs_strip_i(format_line(v, attach)); |
| 123 | 140 | ||
| 124 | if (xs_startswith(ss, ">")) { | 141 | if (xs_startswith(ss, ">")) { |
| 125 | /* delete the > and subsequent spaces */ | 142 | /* delete the > and subsequent spaces */ |
| @@ -322,7 +322,7 @@ d_char *html_user_header(snac *snac, d_char *s, int local) | |||
| 322 | s = xs_str_cat(s, s1); | 322 | s = xs_str_cat(s, s1); |
| 323 | 323 | ||
| 324 | if (local) { | 324 | if (local) { |
| 325 | xs *bio = not_really_markdown(xs_dict_get(snac->config, "bio")); | 325 | xs *bio = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL); |
| 326 | xs *s1 = xs_fmt("<div class=\"p-note snac-top-user-bio\">%s</div>\n", bio); | 326 | xs *s1 = xs_fmt("<div class=\"p-note snac-top-user-bio\">%s</div>\n", bio); |
| 327 | 327 | ||
| 328 | s = xs_str_cat(s, s1); | 328 | s = xs_str_cat(s, s1); |
| @@ -1467,7 +1467,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 1467 | if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/ | 1467 | if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/ |
| 1468 | d_char *rss; | 1468 | d_char *rss; |
| 1469 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); | 1469 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); |
| 1470 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio")); | 1470 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); |
| 1471 | char *p, *v; | 1471 | char *p, *v; |
| 1472 | 1472 | ||
| 1473 | /* escape tags */ | 1473 | /* escape tags */ |
| @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) | |||
| 87 | if (strcmp(cmd, "markdown") == 0) { | 87 | if (strcmp(cmd, "markdown") == 0) { |
| 88 | /* undocumented, for testing only */ | 88 | /* undocumented, for testing only */ |
| 89 | xs *c = xs_readall(stdin); | 89 | xs *c = xs_readall(stdin); |
| 90 | xs *fc = not_really_markdown(c); | 90 | xs *fc = not_really_markdown(c, NULL); |
| 91 | 91 | ||
| 92 | printf("<html>\n%s\n</html>\n", fc); | 92 | printf("<html>\n%s\n</html>\n", fc); |
| 93 | return 0; | 93 | return 0; |
| @@ -228,7 +228,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, | |||
| 228 | char *payload, int p_size, | 228 | char *payload, int p_size, |
| 229 | char **body, int *b_size, char **ctype); | 229 | char **body, int *b_size, char **ctype); |
| 230 | 230 | ||
| 231 | xs_str *not_really_markdown(const char *content); | 231 | xs_str *not_really_markdown(const char *content, xs_list **attach); |
| 232 | xs_str *sanitize(const char *content); | 232 | xs_str *sanitize(const char *content); |
| 233 | 233 | ||
| 234 | int html_get_handler(const xs_dict *req, const char *q_path, | 234 | int html_get_handler(const xs_dict *req, const char *q_path, |