commit 3d677f6
default
·
2025-01-21 13:33:21 +0000 UTC
parent 7add876
Added more Markdown (contributed by an-im-dugud).
1 files changed,
+46,
-1
M
format.c
M
format.c
+46,
-1
1@@ -92,6 +92,8 @@ static xs_str *format_line(const char *line, xs_list **attach)
2 "`[^`]+`" "|"
3 "~~[^~]+~~" "|"
4 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|"
5+ "_[^_]+_" "|" //anzu
6+ "__[^_]+__" "|" //anzu
7 "!\\[[^]]+\\]\\([^\\)]+\\)" "|"
8 "\\[[^]]+\\]\\([^\\)]+\\)" "|"
9 "[a-z]+:/" "/[^[:space:]]+" "|"
10@@ -127,6 +129,20 @@ static xs_str *format_line(const char *line, xs_list **attach)
11 xs *s2 = xs_fmt("<i>%s</i>", s1);
12 s = xs_str_cat(s, s2);
13 }
14+ //anzu - begin
15+ else
16+ if (xs_startswith(v, "__")) {
17+ xs *s1 = xs_strip_chars_i(xs_dup(v), "_");
18+ xs *s2 = xs_fmt("<u>%s</u>", s1);
19+ s = xs_str_cat(s, s2);
20+ }
21+ else
22+ if (xs_startswith(v, "_")) {
23+ xs *s1 = xs_strip_chars_i(xs_dup(v), "_");
24+ xs *s2 = xs_fmt("<i>%s</i>", s1);
25+ s = xs_str_cat(s, s2);
26+ }
27+ //anzu - end
28 else
29 if (xs_startswith(v, "~~")) {
30 xs *s1 = xs_strip_chars_i(xs_dup(v), "~");
31@@ -303,6 +319,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
32 continue;
33 }
34
35+ //anzu - begin
36+ // h1 reserved for snac?
37+ if (xs_startswith(ss, "# ")) {
38+ ss = xs_strip_i(xs_crop_i(ss, 2, 0));
39+ s = xs_str_cat(s, "<h2>");
40+ s = xs_str_cat(s, ss);
41+ s = xs_str_cat(s, "</h2>");
42+ continue;
43+ }
44+ if (xs_startswith(ss, "## ")) {
45+ ss = xs_strip_i(xs_crop_i(ss, 3, 0));
46+ s = xs_str_cat(s, "<h2>");
47+ s = xs_str_cat(s, ss);
48+ s = xs_str_cat(s, "</h2>");
49+ continue;
50+ }
51+ if (xs_startswith(ss, "### ")) {
52+ ss = xs_strip_i(xs_crop_i(ss, 4, 0));
53+ s = xs_str_cat(s, "<h3>");
54+ s = xs_str_cat(s, ss);
55+ s = xs_str_cat(s, "</h3>");
56+ continue;
57+ }
58+ //anzu - end
59+
60 if (xs_startswith(ss, ">")) {
61 /* delete the > and subsequent spaces */
62 ss = xs_strip_i(xs_crop_i(ss, 1, 0));
63@@ -336,6 +377,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
64 s = xs_replace_i(s, "<br><br><blockquote>", "<br><blockquote>");
65 s = xs_replace_i(s, "</blockquote><br>", "</blockquote>");
66 s = xs_replace_i(s, "</pre><br>", "</pre>");
67+ s = xs_replace_i(s, "</h2><br>", "</h2>"); //anzu ???
68+ s = xs_replace_i(s, "</h3><br>", "</h3>"); //anzu ???
69
70 {
71 /* traditional emoticons */
72@@ -378,7 +421,9 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
73
74 const char *valid_tags[] = {
75 "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "small",
76- "span", "i", "b", "u", "s", "pre", "code", "em", "strong", "hr", "img", "del", "bdi", NULL
77+ "span", "i", "b", "u", "s", "pre", "code", "em", "strong", "hr", "img", "del", "bdi",
78+ "h2","h3", //anzu
79+ NULL
80 };
81
82 xs_str *sanitize(const char *content)