diff options
-rw-r--r-- | doc/snac.5 | 5 | ||||
-rw-r--r-- | format.c | 31 |
2 files changed, 36 insertions, 0 deletions
@@ -43,6 +43,11 @@ int main(int argc, char *argv[]) Standalone URLs are converted to links. Also, from version 2.54, markdown-style links in the form of [link label](url) are also supported. +.It attached images +Standalone URLs for which the final extension is recognized as an +image (.jpg, .gif, .png, etc), are converted to ActivityPub image +attachments. Also, from version 2.57, markdown-style image links +in the form of  are also supported. .It line separators Horizonal rules can be inserted by typing three minus symbols alone in a line. @@ -91,6 +91,7 @@ static xs_str *format_line(const char *line, xs_list **attach) "`[^`]+`" "|" "~~[^~]+~~" "|" "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" + "!\\[[^]]+\\]\\([^\\)]+\\)" "|" "\\[[^]]+\\]\\([^\\)]+\\)" "|" "https?:/" "/[^[:space:]]+" ")"); @@ -170,6 +171,36 @@ static xs_str *format_line(const char *line, xs_list **attach) s = xs_str_cat(s, v); } else + if (*v == '!') { + /* markdown-like images  */ + xs *w = xs_strip_chars_i(xs_replace(v, "#", "#"), "; + + if (xs_list_len(l) == 2) { + const char *alt_text = xs_list_get(l, 0); + const char *img_url = xs_list_get(l, 1); + const char *mime = xs_mime_by_ext(img_url); + + if (attach != NULL && xs_startswith(mime, "image/")) { + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "mediaType", mime); + d = xs_dict_append(d, "url", img_url); + d = xs_dict_append(d, "name", alt_text); + d = xs_dict_append(d, "type", "Image"); + + *attach = xs_list_append(*attach, d); + } + else { + xs *link = xs_fmt("<a href=\"%s\">%s</a>", img_url, alt_text); + + s = xs_str_cat(s, link); + } + } + else + s = xs_str_cat(s, v); + } + else s = xs_str_cat(s, v); } else |