commit c6c5150

grunfink  ·  2025-08-27 07:54:33 +0000 UTC
parent 41b4936
Added Markdown support for bullets (unsorted lists).
1 files changed,  +21, -0
+21, -0
 1@@ -278,6 +278,7 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
 2     xs_str *s  = xs_str_new(NULL);
 3     int in_pre = 0;
 4     int in_blq = 0;
 5+    int in_ul = 0;
 6     xs *list;
 7     char *p;
 8     const char *v;
 9@@ -361,11 +362,30 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
10             continue;
11         }
12 
13+        if (xs_startswith(ss, "* ") || xs_startswith(ss, "- ")) {
14+            /* unsorted list */
15+            ss = xs_strip_i(xs_crop_i(ss, 1, 0));
16+
17+            if (!in_ul) {
18+                s = xs_str_cat(s, "<ul>");
19+                in_ul = 1;
20+            }
21+
22+            s = xs_str_cat(s, "<li>", ss);
23+
24+            continue;
25+        }
26+
27         if (in_blq) {
28             s = xs_str_cat(s, "</blockquote>");
29             in_blq = 0;
30         }
31 
32+        if (in_ul) {
33+            s = xs_str_cat(s, "</ul>");
34+            in_ul = 0;
35+        }
36+
37         s = xs_str_cat(s, ss);
38         s = xs_str_cat(s, "<br>");
39     }
40@@ -379,6 +399,7 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
41     s = xs_replace_i(s, "<br><br><blockquote>", "<br><blockquote>");
42     s = xs_replace_i(s, "</blockquote><br>", "</blockquote>");
43     s = xs_replace_i(s, "</pre><br>", "</pre>");
44+    s = xs_replace_i(s, "</ul><br>", "</ul>");
45     s = xs_replace_i(s, "</h2><br>", "</h2>"); //anzu ???
46     s = xs_replace_i(s, "</h3><br>", "</h3>"); //anzu ???
47