diff options
| author | 2025-01-27 18:07:00 +0000 | |
|---|---|---|
| committer | 2025-01-27 18:07:00 +0000 | |
| commit | f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3 (patch) | |
| tree | 72334e7a24b997957d201490681552b6b1ad2e2f /format.c | |
| parent | Add short_description_raw option (diff) | |
| parent | Fixed crash in the notification area after deleting a post. (diff) | |
| download | penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.tar.gz penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.tar.xz penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.zip | |
Merge branch 'master' into master
Diffstat (limited to 'format.c')
| -rw-r--r-- | format.c | 49 |
1 files changed, 47 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | 1 | /* snac - A simple, minimalistic ActivityPub instance */ |
| 2 | /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ | 2 | /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ |
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_regex.h" | 5 | #include "xs_regex.h" |
| @@ -92,6 +92,8 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 92 | "`[^`]+`" "|" | 92 | "`[^`]+`" "|" |
| 93 | "~~[^~]+~~" "|" | 93 | "~~[^~]+~~" "|" |
| 94 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" | 94 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" |
| 95 | "_[^_]+_" "|" //anzu | ||
| 96 | "__[^_]+__" "|" //anzu | ||
| 95 | "!\\[[^]]+\\]\\([^\\)]+\\)" "|" | 97 | "!\\[[^]]+\\]\\([^\\)]+\\)" "|" |
| 96 | "\\[[^]]+\\]\\([^\\)]+\\)" "|" | 98 | "\\[[^]]+\\]\\([^\\)]+\\)" "|" |
| 97 | "[a-z]+:/" "/[^[:space:]]+" "|" | 99 | "[a-z]+:/" "/[^[:space:]]+" "|" |
| @@ -127,6 +129,20 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 127 | xs *s2 = xs_fmt("<i>%s</i>", s1); | 129 | xs *s2 = xs_fmt("<i>%s</i>", s1); |
| 128 | s = xs_str_cat(s, s2); | 130 | s = xs_str_cat(s, s2); |
| 129 | } | 131 | } |
| 132 | //anzu - begin | ||
| 133 | else | ||
| 134 | if (xs_startswith(v, "__")) { | ||
| 135 | xs *s1 = xs_strip_chars_i(xs_dup(v), "_"); | ||
| 136 | xs *s2 = xs_fmt("<u>%s</u>", s1); | ||
| 137 | s = xs_str_cat(s, s2); | ||
| 138 | } | ||
| 139 | else | ||
| 140 | if (xs_startswith(v, "_")) { | ||
| 141 | xs *s1 = xs_strip_chars_i(xs_dup(v), "_"); | ||
| 142 | xs *s2 = xs_fmt("<i>%s</i>", s1); | ||
| 143 | s = xs_str_cat(s, s2); | ||
| 144 | } | ||
| 145 | //anzu - end | ||
| 130 | else | 146 | else |
| 131 | if (xs_startswith(v, "~~")) { | 147 | if (xs_startswith(v, "~~")) { |
| 132 | xs *s1 = xs_strip_chars_i(xs_dup(v), "~"); | 148 | xs *s1 = xs_strip_chars_i(xs_dup(v), "~"); |
| @@ -303,6 +319,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag | |||
| 303 | continue; | 319 | continue; |
| 304 | } | 320 | } |
| 305 | 321 | ||
| 322 | //anzu - begin | ||
| 323 | // h1 reserved for snac? | ||
| 324 | if (xs_startswith(ss, "# ")) { | ||
| 325 | ss = xs_strip_i(xs_crop_i(ss, 2, 0)); | ||
| 326 | s = xs_str_cat(s, "<h2>"); | ||
| 327 | s = xs_str_cat(s, ss); | ||
| 328 | s = xs_str_cat(s, "</h2>"); | ||
| 329 | continue; | ||
| 330 | } | ||
| 331 | if (xs_startswith(ss, "## ")) { | ||
| 332 | ss = xs_strip_i(xs_crop_i(ss, 3, 0)); | ||
| 333 | s = xs_str_cat(s, "<h2>"); | ||
| 334 | s = xs_str_cat(s, ss); | ||
| 335 | s = xs_str_cat(s, "</h2>"); | ||
| 336 | continue; | ||
| 337 | } | ||
| 338 | if (xs_startswith(ss, "### ")) { | ||
| 339 | ss = xs_strip_i(xs_crop_i(ss, 4, 0)); | ||
| 340 | s = xs_str_cat(s, "<h3>"); | ||
| 341 | s = xs_str_cat(s, ss); | ||
| 342 | s = xs_str_cat(s, "</h3>"); | ||
| 343 | continue; | ||
| 344 | } | ||
| 345 | //anzu - end | ||
| 346 | |||
| 306 | if (xs_startswith(ss, ">")) { | 347 | if (xs_startswith(ss, ">")) { |
| 307 | /* delete the > and subsequent spaces */ | 348 | /* delete the > and subsequent spaces */ |
| 308 | ss = xs_strip_i(xs_crop_i(ss, 1, 0)); | 349 | ss = xs_strip_i(xs_crop_i(ss, 1, 0)); |
| @@ -336,6 +377,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag | |||
| 336 | s = xs_replace_i(s, "<br><br><blockquote>", "<br><blockquote>"); | 377 | s = xs_replace_i(s, "<br><br><blockquote>", "<br><blockquote>"); |
| 337 | s = xs_replace_i(s, "</blockquote><br>", "</blockquote>"); | 378 | s = xs_replace_i(s, "</blockquote><br>", "</blockquote>"); |
| 338 | s = xs_replace_i(s, "</pre><br>", "</pre>"); | 379 | s = xs_replace_i(s, "</pre><br>", "</pre>"); |
| 380 | s = xs_replace_i(s, "</h2><br>", "</h2>"); //anzu ??? | ||
| 381 | s = xs_replace_i(s, "</h3><br>", "</h3>"); //anzu ??? | ||
| 339 | 382 | ||
| 340 | { | 383 | { |
| 341 | /* traditional emoticons */ | 384 | /* traditional emoticons */ |
| @@ -378,7 +421,9 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag | |||
| 378 | 421 | ||
| 379 | const char *valid_tags[] = { | 422 | const char *valid_tags[] = { |
| 380 | "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "small", | 423 | "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "small", |
| 381 | "span", "i", "b", "u", "s", "pre", "code", "em", "strong", "hr", "img", "del", "bdi", NULL | 424 | "span", "i", "b", "u", "s", "pre", "code", "em", "strong", "hr", "img", "del", "bdi", |
| 425 | "h2","h3", //anzu | ||
| 426 | NULL | ||
| 382 | }; | 427 | }; |
| 383 | 428 | ||
| 384 | xs_str *sanitize(const char *content) | 429 | xs_str *sanitize(const char *content) |