Browse Source

Added support for Markdown ~~strikethrough text~~.

default 9 months ago
parent
commit
6e3b621f7b
2 changed files with 17 additions and 7 deletions
  1. 5 3
      doc/snac.5
  2. 12 4
      format.c

+ 5 - 3
doc/snac.5

@@ -25,6 +25,8 @@ A special subset of Markdown is allowed, including:
 **text between two pairs of asterisks**
 .It italic
 *text between a pair of asterisks*
+.It strikethrough text
+~~text between a pair of tildes~~
 .It code
 Text `between backticks` is formatted as code.
 .Bd -literal
@@ -41,16 +43,16 @@ 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 Line separators
+.It line separators
 Horizonal rules can be inserted by typing three minus symbols
 alone in a line.
 .It quoted text
 Lines starting with >.
-.It User Mentions
+.It user mentions
 Strings in the format @user@host are requested using the Webfinger
 protocol and converted to links and mentions if something reasonable
 is found.
-.It Emoticons / Smileys / Silly Symbols
+.It emoticons /emojis / smileys / silly symbols
 (Note: from version 2.51, these symbols are configurable by the
 instance administrator, so the available ones may differ).
 .Pp

+ 12 - 4
format.c

@@ -89,6 +89,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
     xs *sm = xs_regex_split(line,
         "("
             "`[^`]+`"                           "|"
+            "~~[^~]+~~"                         "|"
             "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*"     "|"
             "\\[[^]]+\\]\\([^\\)]+\\)"          "|"
             "https?:/" "/[^[:space:]]+"
@@ -100,30 +101,37 @@ static xs_str *format_line(const char *line, xs_list **attach)
         if ((n & 0x1)) {
             /* markup */
             if (xs_startswith(v, "`")) {
-                xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
+                xs *s1 = xs_strip_chars_i(xs_dup(v), "`");
                 xs *e1 = encode_html(s1);
                 xs *s2 = xs_fmt("<code>%s</code>", e1);
                 s = xs_str_cat(s, s2);
             }
             else
             if (xs_startswith(v, "***")) {
-                xs *s1 = xs_crop_i(xs_dup(v), 3, -3);
+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
                 xs *s2 = xs_fmt("<b><i>%s</i></b>", s1);
                 s = xs_str_cat(s, s2);
             }
             else
             if (xs_startswith(v, "**")) {
-                xs *s1 = xs_crop_i(xs_dup(v), 2, -2);
+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
                 xs *s2 = xs_fmt("<b>%s</b>", s1);
                 s = xs_str_cat(s, s2);
             }
             else
             if (xs_startswith(v, "*")) {
-                xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
+                xs *s1 = xs_strip_chars_i(xs_dup(v), "*");
                 xs *s2 = xs_fmt("<i>%s</i>", s1);
                 s = xs_str_cat(s, s2);
             }
             else
+            if (xs_startswith(v, "~~")) {
+                xs *s1 = xs_strip_chars_i(xs_dup(v), "~");
+                xs *e1 = encode_html(s1);
+                xs *s2 = xs_fmt("<s>%s</s>", e1);
+                s = xs_str_cat(s, s2);
+            }
+            else
             if (xs_startswith(v, "http")) {
                 xs *u  = xs_replace(v, "#", "&#35;");
                 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");