summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-03-25 16:15:09 +0100
committerdefault <nobody@localhost>2024-03-25 16:15:09 +0100
commitadf0a13992edb85738ac983a872937a805629474 (patch)
tree31e084c9ff92a82e2083e8225e703bceeec56981
parentbc752b7d67d834455eae9eacec16e28585c79c5f (diff)
If an emoji in emojis.json is an URL to an image, it's stored in the tag list.
-rw-r--r--activitypub.c4
-rw-r--r--format.c29
-rw-r--r--html.c4
-rw-r--r--main.c2
-rw-r--r--mastoapi.c2
-rw-r--r--snac.h2
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)
msg = xs_dict_set(msg, "preferredUsername", snac->uid);
msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published"));
- xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL);
+ xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL, NULL);
f_bio = process_tags(snac, f_bio_2, &tags);
msg = xs_dict_set(msg, "summary", f_bio);
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,
}
/* format the content */
- fc2 = not_really_markdown(content, &atls);
+ fc2 = not_really_markdown(content, &atls, &tag);
if (in_reply_to != NULL && *in_reply_to) {
xs *p_msg = NULL;
diff --git a/format.c b/format.c
index 06e006a..f89fe21 100644
--- a/format.c
+++ b/format.c
@@ -6,6 +6,7 @@
#include "xs_mime.h"
#include "xs_html.h"
#include "xs_json.h"
+#include "xs_time.h"
#include "snac.h"
@@ -140,7 +141,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
}
-xs_str *not_really_markdown(const char *content, xs_list **attach)
+xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag)
/* formats a content using some Markdown rules */
{
xs_str *s = xs_str_new(NULL);
@@ -229,7 +230,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
char *k, *v;
while (xs_dict_next(d, &k, &v, &c)) {
- s = xs_replace_i(s, k, v);
+ const char *t = NULL;
+
+ /* is it an URL to an image? */
+ if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) {
+ if (tag) {
+ /* add the emoji to the tag list */
+ xs *e = xs_dict_new();
+ xs *i = xs_dict_new();
+ xs *u = xs_str_utctime(0, ISO_DATE_SPEC);
+
+ e = xs_dict_append(e, "id", v);
+ e = xs_dict_append(e, "type", "Emoji");
+ e = xs_dict_append(e, "name", k);
+ e = xs_dict_append(e, "updated", u);
+
+ i = xs_dict_append(i, "type", "Image");
+ i = xs_dict_append(i, "mediaType", t);
+ i = xs_dict_append(i, "url", v);
+ e = xs_dict_append(e, "icon", i);
+
+ *tag = xs_list_append(*tag, e);
+ }
+ }
+ else
+ s = xs_replace_i(s, k, v);
}
}
diff --git a/html.c b/html.c
index c2098ed..60682f9 100644
--- a/html.c
+++ b/html.c
@@ -775,7 +775,7 @@ static xs_html *html_user_body(snac *user, int read_only)
if (read_only) {
xs *es1 = encode_html(xs_dict_get(user->config, "bio"));
- xs *bio1 = not_really_markdown(es1, NULL);
+ xs *bio1 = not_really_markdown(es1, NULL, NULL);
xs *tags = xs_list_new();
xs *bio2 = process_tags(user, bio1, &tags);
@@ -2657,7 +2657,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
return 403;
xs *elems = timeline_simple_list(&snac, "public", 0, 20);
- xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
+ xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL, NULL);
xs *rss_title = xs_fmt("%s (@%s@%s)",
xs_dict_get(snac.config, "name"),
diff --git a/main.c b/main.c
index c789299..d609880 100644
--- a/main.c
+++ b/main.c
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
if (strcmp(cmd, "markdown") == 0) { /** **/
/* undocumented, for testing only */
xs *c = xs_readall(stdin);
- xs *fc = not_really_markdown(c, NULL);
+ xs *fc = not_really_markdown(c, NULL, NULL);
printf("<html>\n%s\n</html>\n", fc);
return 0;
diff --git a/mastoapi.c b/mastoapi.c
index 0ec1429..fab71f1 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -2717,7 +2717,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) {
const char *content = xs_dict_get(args, "status");
xs *atls = xs_list_new();
- xs *f_content = not_really_markdown(content, &atls);
+ xs *f_content = not_really_markdown(content, &atls, NULL);
/* replace fields with new content */
msg = xs_dict_set(msg, "sourceContent", content);
diff --git a/snac.h b/snac.h
index 2953af7..0e59f33 100644
--- a/snac.h
+++ b/snac.h
@@ -305,7 +305,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype);
xs_dict *emojis(void);
-xs_str *not_really_markdown(const char *content, xs_list **attach);
+xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
xs_str *sanitize(const char *content);
xs_str *encode_html(const char *str);