commit adf0a13
default
·
2024-03-25 15:15:09 +0000 UTC
parent bc752b7
If an emoji in emojis.json is an URL to an image, it's stored in the tag list.
6 files changed,
+34,
-9
+2,
-2
1@@ -1190,7 +1190,7 @@ xs_dict *msg_actor(snac *snac)
2 msg = xs_dict_set(msg, "preferredUsername", snac->uid);
3 msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published"));
4
5- xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL);
6+ xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL, NULL);
7 f_bio = process_tags(snac, f_bio_2, &tags);
8 msg = xs_dict_set(msg, "summary", f_bio);
9 msg = xs_dict_set(msg, "tag", tags);
10@@ -1398,7 +1398,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
11 }
12
13 /* format the content */
14- fc2 = not_really_markdown(content, &atls);
15+ fc2 = not_really_markdown(content, &atls, &tag);
16
17 if (in_reply_to != NULL && *in_reply_to) {
18 xs *p_msg = NULL;
M
format.c
+27,
-2
1@@ -6,6 +6,7 @@
2 #include "xs_mime.h"
3 #include "xs_html.h"
4 #include "xs_json.h"
5+#include "xs_time.h"
6
7 #include "snac.h"
8
9@@ -140,7 +141,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
10 }
11
12
13-xs_str *not_really_markdown(const char *content, xs_list **attach)
14+xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag)
15 /* formats a content using some Markdown rules */
16 {
17 xs_str *s = xs_str_new(NULL);
18@@ -229,7 +230,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
19 char *k, *v;
20
21 while (xs_dict_next(d, &k, &v, &c)) {
22- s = xs_replace_i(s, k, v);
23+ const char *t = NULL;
24+
25+ /* is it an URL to an image? */
26+ if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) {
27+ if (tag) {
28+ /* add the emoji to the tag list */
29+ xs *e = xs_dict_new();
30+ xs *i = xs_dict_new();
31+ xs *u = xs_str_utctime(0, ISO_DATE_SPEC);
32+
33+ e = xs_dict_append(e, "id", v);
34+ e = xs_dict_append(e, "type", "Emoji");
35+ e = xs_dict_append(e, "name", k);
36+ e = xs_dict_append(e, "updated", u);
37+
38+ i = xs_dict_append(i, "type", "Image");
39+ i = xs_dict_append(i, "mediaType", t);
40+ i = xs_dict_append(i, "url", v);
41+ e = xs_dict_append(e, "icon", i);
42+
43+ *tag = xs_list_append(*tag, e);
44+ }
45+ }
46+ else
47+ s = xs_replace_i(s, k, v);
48 }
49 }
50
M
html.c
+2,
-2
1@@ -775,7 +775,7 @@ static xs_html *html_user_body(snac *user, int read_only)
2
3 if (read_only) {
4 xs *es1 = encode_html(xs_dict_get(user->config, "bio"));
5- xs *bio1 = not_really_markdown(es1, NULL);
6+ xs *bio1 = not_really_markdown(es1, NULL, NULL);
7 xs *tags = xs_list_new();
8 xs *bio2 = process_tags(user, bio1, &tags);
9
10@@ -2657,7 +2657,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
11 return 403;
12
13 xs *elems = timeline_simple_list(&snac, "public", 0, 20);
14- xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
15+ xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL, NULL);
16
17 xs *rss_title = xs_fmt("%s (@%s@%s)",
18 xs_dict_get(snac.config, "name"),
M
main.c
+1,
-1
1@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
2 if (strcmp(cmd, "markdown") == 0) { /** **/
3 /* undocumented, for testing only */
4 xs *c = xs_readall(stdin);
5- xs *fc = not_really_markdown(c, NULL);
6+ xs *fc = not_really_markdown(c, NULL, NULL);
7
8 printf("<html>\n%s\n</html>\n", fc);
9 return 0;
+1,
-1
1@@ -2717,7 +2717,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
2 if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) {
3 const char *content = xs_dict_get(args, "status");
4 xs *atls = xs_list_new();
5- xs *f_content = not_really_markdown(content, &atls);
6+ xs *f_content = not_really_markdown(content, &atls, NULL);
7
8 /* replace fields with new content */
9 msg = xs_dict_set(msg, "sourceContent", content);
M
snac.h
+1,
-1
1@@ -305,7 +305,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
2 char **body, int *b_size, char **ctype);
3
4 xs_dict *emojis(void);
5-xs_str *not_really_markdown(const char *content, xs_list **attach);
6+xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
7 xs_str *sanitize(const char *content);
8 xs_str *encode_html(const char *str);
9