commit 6e3b621

default  ·  2024-07-19 05:11:25 +0000 UTC
parent f3b392e
Added support for Markdown ~~strikethrough text~~.
2 files changed,  +17, -7
+5, -3
 1@@ -25,6 +25,8 @@ A special subset of Markdown is allowed, including:
 2 **text between two pairs of asterisks**
 3 .It italic
 4 *text between a pair of asterisks*
 5+.It strikethrough text
 6+~~text between a pair of tildes~~
 7 .It code
 8 Text `between backticks` is formatted as code.
 9 .Bd -literal
10@@ -41,16 +43,16 @@ int main(int argc, char *argv[])
11 Standalone URLs are converted to links. Also, from version 2.54,
12 markdown-style links in the form of [link label](url) are also
13 supported.
14-.It Line separators
15+.It line separators
16 Horizonal rules can be inserted by typing three minus symbols
17 alone in a line.
18 .It quoted text
19 Lines starting with >.
20-.It User Mentions
21+.It user mentions
22 Strings in the format @user@host are requested using the Webfinger
23 protocol and converted to links and mentions if something reasonable
24 is found.
25-.It Emoticons / Smileys / Silly Symbols
26+.It emoticons /emojis / smileys / silly symbols
27 (Note: from version 2.51, these symbols are configurable by the
28 instance administrator, so the available ones may differ).
29 .Pp
+12, -4
 1@@ -89,6 +89,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
 2     xs *sm = xs_regex_split(line,
 3         "("
 4             "`[^`]+`"                           "|"
 5+            "~~[^~]+~~"                         "|"
 6             "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*"     "|"
 7             "\\[[^]]+\\]\\([^\\)]+\\)"          "|"
 8             "https?:/" "/[^[:space:]]+"
 9@@ -100,30 +101,37 @@ static xs_str *format_line(const char *line, xs_list **attach)
10         if ((n & 0x1)) {
11             /* markup */
12             if (xs_startswith(v, "`")) {
13-                xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
14+                xs *s1 = xs_strip_chars_i(xs_dup(v), "`");
15                 xs *e1 = encode_html(s1);
16                 xs *s2 = xs_fmt("<code>%s</code>", e1);
17                 s = xs_str_cat(s, s2);
18             }
19             else
20             if (xs_startswith(v, "***")) {
21-                xs *s1 = xs_crop_i(xs_dup(v), 3, -3);
22+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
23                 xs *s2 = xs_fmt("<b><i>%s</i></b>", s1);
24                 s = xs_str_cat(s, s2);
25             }
26             else
27             if (xs_startswith(v, "**")) {
28-                xs *s1 = xs_crop_i(xs_dup(v), 2, -2);
29+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
30                 xs *s2 = xs_fmt("<b>%s</b>", s1);
31                 s = xs_str_cat(s, s2);
32             }
33             else
34             if (xs_startswith(v, "*")) {
35-                xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
36+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
37                 xs *s2 = xs_fmt("<i>%s</i>", s1);
38                 s = xs_str_cat(s, s2);
39             }
40             else
41+            if (xs_startswith(v, "~~")) {
42+                xs *s1 = xs_strip_chars_i(xs_dup(v), "~");
43+                xs *e1 = encode_html(s1);
44+                xs *s2 = xs_fmt("<s>%s</s>", e1);
45+                s = xs_str_cat(s, s2);
46+            }
47+            else
48             if (xs_startswith(v, "http")) {
49                 xs *u  = xs_replace(v, "#", "&#35;");
50                 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");