summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/snac.55
-rw-r--r--format.c31
2 files changed, 36 insertions, 0 deletions
diff --git a/doc/snac.5 b/doc/snac.5
index 1b07155..fc991b2 100644
--- a/doc/snac.5
+++ b/doc/snac.5
@@ -43,6 +43,11 @@ int main(int argc, char *argv[])
43Standalone URLs are converted to links. Also, from version 2.54, 43Standalone URLs are converted to links. Also, from version 2.54,
44markdown-style links in the form of [link label](url) are also 44markdown-style links in the form of [link label](url) are also
45supported. 45supported.
46.It attached images
47Standalone URLs for which the final extension is recognized as an
48image (.jpg, .gif, .png, etc), are converted to ActivityPub image
49attachments. Also, from version 2.57, markdown-style image links
50in the form of ![alt text](image url) are also supported.
46.It line separators 51.It line separators
47Horizonal rules can be inserted by typing three minus symbols 52Horizonal rules can be inserted by typing three minus symbols
48alone in a line. 53alone in a line.
diff --git a/format.c b/format.c
index 170d28a..573b702 100644
--- a/format.c
+++ b/format.c
@@ -91,6 +91,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
91 "`[^`]+`" "|" 91 "`[^`]+`" "|"
92 "~~[^~]+~~" "|" 92 "~~[^~]+~~" "|"
93 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" 93 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|"
94 "!\\[[^]]+\\]\\([^\\)]+\\)" "|"
94 "\\[[^]]+\\]\\([^\\)]+\\)" "|" 95 "\\[[^]]+\\]\\([^\\)]+\\)" "|"
95 "https?:/" "/[^[:space:]]+" 96 "https?:/" "/[^[:space:]]+"
96 ")"); 97 ")");
@@ -170,6 +171,36 @@ static xs_str *format_line(const char *line, xs_list **attach)
170 s = xs_str_cat(s, v); 171 s = xs_str_cat(s, v);
171 } 172 }
172 else 173 else
174 if (*v == '!') {
175 /* markdown-like images ![alt text](url to image) */
176 xs *w = xs_strip_chars_i(xs_replace(v, "#", "#"), "![)");
177 xs *l = xs_split_n(w, "](", 1);
178
179 if (xs_list_len(l) == 2) {
180 const char *alt_text = xs_list_get(l, 0);
181 const char *img_url = xs_list_get(l, 1);
182 const char *mime = xs_mime_by_ext(img_url);
183
184 if (attach != NULL && xs_startswith(mime, "image/")) {
185 xs *d = xs_dict_new();
186
187 d = xs_dict_append(d, "mediaType", mime);
188 d = xs_dict_append(d, "url", img_url);
189 d = xs_dict_append(d, "name", alt_text);
190 d = xs_dict_append(d, "type", "Image");
191
192 *attach = xs_list_append(*attach, d);
193 }
194 else {
195 xs *link = xs_fmt("<a href=\"%s\">%s</a>", img_url, alt_text);
196
197 s = xs_str_cat(s, link);
198 }
199 }
200 else
201 s = xs_str_cat(s, v);
202 }
203 else
173 s = xs_str_cat(s, v); 204 s = xs_str_cat(s, v);
174 } 205 }
175 else 206 else