diff options
| author | 2024-07-19 07:11:25 +0200 | |
|---|---|---|
| committer | 2024-07-19 07:11:25 +0200 | |
| commit | 6e3b621f7b84844ce18eb953fc7fba806472bef8 (patch) | |
| tree | c22e65d60fd710ed2affcd255acc3e0d7e4f0b01 /format.c | |
| parent | Show bold+italic (text between ***) correctly. (diff) | |
| download | snac2-6e3b621f7b84844ce18eb953fc7fba806472bef8.tar.gz snac2-6e3b621f7b84844ce18eb953fc7fba806472bef8.tar.xz snac2-6e3b621f7b84844ce18eb953fc7fba806472bef8.zip | |
Added support for Markdown ~~strikethrough text~~.
Diffstat (limited to 'format.c')
| -rw-r--r-- | format.c | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -89,6 +89,7 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 89 | xs *sm = xs_regex_split(line, | 89 | xs *sm = xs_regex_split(line, |
| 90 | "(" | 90 | "(" |
| 91 | "`[^`]+`" "|" | 91 | "`[^`]+`" "|" |
| 92 | "~~[^~]+~~" "|" | ||
| 92 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" | 93 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" |
| 93 | "\\[[^]]+\\]\\([^\\)]+\\)" "|" | 94 | "\\[[^]]+\\]\\([^\\)]+\\)" "|" |
| 94 | "https?:/" "/[^[:space:]]+" | 95 | "https?:/" "/[^[:space:]]+" |
| @@ -100,30 +101,37 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 100 | if ((n & 0x1)) { | 101 | if ((n & 0x1)) { |
| 101 | /* markup */ | 102 | /* markup */ |
| 102 | if (xs_startswith(v, "`")) { | 103 | if (xs_startswith(v, "`")) { |
| 103 | xs *s1 = xs_crop_i(xs_dup(v), 1, -1); | 104 | xs *s1 = xs_strip_chars_i(xs_dup(v), "`"); |
| 104 | xs *e1 = encode_html(s1); | 105 | xs *e1 = encode_html(s1); |
| 105 | xs *s2 = xs_fmt("<code>%s</code>", e1); | 106 | xs *s2 = xs_fmt("<code>%s</code>", e1); |
| 106 | s = xs_str_cat(s, s2); | 107 | s = xs_str_cat(s, s2); |
| 107 | } | 108 | } |
| 108 | else | 109 | else |
| 109 | if (xs_startswith(v, "***")) { | 110 | if (xs_startswith(v, "***")) { |
| 110 | xs *s1 = xs_crop_i(xs_dup(v), 3, -3); | 111 | xs *s1 = xs_strip_chars_i(xs_dup(v), "*"); |
| 111 | xs *s2 = xs_fmt("<b><i>%s</i></b>", s1); | 112 | xs *s2 = xs_fmt("<b><i>%s</i></b>", s1); |
| 112 | s = xs_str_cat(s, s2); | 113 | s = xs_str_cat(s, s2); |
| 113 | } | 114 | } |
| 114 | else | 115 | else |
| 115 | if (xs_startswith(v, "**")) { | 116 | if (xs_startswith(v, "**")) { |
| 116 | xs *s1 = xs_crop_i(xs_dup(v), 2, -2); | 117 | xs *s1 = xs_strip_chars_i(xs_dup(v), "*"); |
| 117 | xs *s2 = xs_fmt("<b>%s</b>", s1); | 118 | xs *s2 = xs_fmt("<b>%s</b>", s1); |
| 118 | s = xs_str_cat(s, s2); | 119 | s = xs_str_cat(s, s2); |
| 119 | } | 120 | } |
| 120 | else | 121 | else |
| 121 | if (xs_startswith(v, "*")) { | 122 | if (xs_startswith(v, "*")) { |
| 122 | xs *s1 = xs_crop_i(xs_dup(v), 1, -1); | 123 | xs *s1 = xs_strip_chars_i(xs_dup(v), "*"); |
| 123 | xs *s2 = xs_fmt("<i>%s</i>", s1); | 124 | xs *s2 = xs_fmt("<i>%s</i>", s1); |
| 124 | s = xs_str_cat(s, s2); | 125 | s = xs_str_cat(s, s2); |
| 125 | } | 126 | } |
| 126 | else | 127 | else |
| 128 | if (xs_startswith(v, "~~")) { | ||
| 129 | xs *s1 = xs_strip_chars_i(xs_dup(v), "~"); | ||
| 130 | xs *e1 = encode_html(s1); | ||
| 131 | xs *s2 = xs_fmt("<s>%s</s>", e1); | ||
| 132 | s = xs_str_cat(s, s2); | ||
| 133 | } | ||
| 134 | else | ||
| 127 | if (xs_startswith(v, "http")) { | 135 | if (xs_startswith(v, "http")) { |
| 128 | xs *u = xs_replace(v, "#", "#"); | 136 | xs *u = xs_replace(v, "#", "#"); |
| 129 | xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)"); | 137 | xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)"); |