summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorGravatar default2025-01-21 14:33:21 +0100
committerGravatar default2025-01-21 14:33:21 +0100
commit3d677f67d845cf6e74271681e76d3cb806036483 (patch)
treeaae0b0d50164c2fccdaa32cb0044502b53ff7199 /format.c
parentUpdated RELEASE_NOTES. (diff)
downloadpenes-snac2-3d677f67d845cf6e74271681e76d3cb806036483.tar.gz
penes-snac2-3d677f67d845cf6e74271681e76d3cb806036483.tar.xz
penes-snac2-3d677f67d845cf6e74271681e76d3cb806036483.zip
Added more Markdown (contributed by an-im-dugud).
Diffstat (limited to 'format.c')
-rw-r--r--format.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/format.c b/format.c
index 52ed3ec..e5934b8 100644
--- a/format.c
+++ b/format.c
@@ -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
379const char *valid_tags[] = { 422const 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
384xs_str *sanitize(const char *content) 429xs_str *sanitize(const char *content)