diff options
| author | 2024-07-19 07:24:28 +0200 | |
|---|---|---|
| committer | 2024-07-19 07:24:28 +0200 | |
| commit | 5f6a42453c168b2fa63fdf15cfd65a5af7fc4680 (patch) | |
| tree | d149ac84f2d3d389d9ff4de2f0e550ef7b67993b | |
| parent | Added support for Markdown ~~strikethrough text~~. (diff) | |
| download | snac2-5f6a42453c168b2fa63fdf15cfd65a5af7fc4680.tar.gz snac2-5f6a42453c168b2fa63fdf15cfd65a5af7fc4680.tar.xz snac2-5f6a42453c168b2fa63fdf15cfd65a5af7fc4680.zip | |
Added support for markdown-like .
| -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[]) | |||
| 43 | Standalone URLs are converted to links. Also, from version 2.54, | 43 | Standalone URLs are converted to links. Also, from version 2.54, |
| 44 | markdown-style links in the form of [link label](url) are also | 44 | markdown-style links in the form of [link label](url) are also |
| 45 | supported. | 45 | supported. |
| 46 | .It attached images | ||
| 47 | Standalone URLs for which the final extension is recognized as an | ||
| 48 | image (.jpg, .gif, .png, etc), are converted to ActivityPub image | ||
| 49 | attachments. Also, from version 2.57, markdown-style image links | ||
| 50 | in the form of  are also supported. | ||
| 46 | .It line separators | 51 | .It line separators |
| 47 | Horizonal rules can be inserted by typing three minus symbols | 52 | Horizonal rules can be inserted by typing three minus symbols |
| 48 | alone in a line. | 53 | alone in a line. |
| @@ -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  */ | ||
| 176 | xs *w = xs_strip_chars_i(xs_replace(v, "#", "#"), "; | ||
| 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 |