commit 8e0ccc6

default  ·  2024-05-26 07:27:36 +0000 UTC
parent 37b6c79
Added markdown-like links.
1 files changed,  +16, -1
+16, -1
 1@@ -87,7 +87,12 @@ static xs_str *format_line(const char *line, xs_list **attach)
 2 
 3     /* split by markup */
 4     xs *sm = xs_regex_split(line,
 5-        "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)");
 6+        "("
 7+            "`[^`]+`"                   "|"
 8+            "\\*\\*?[^\\*]+\\*?\\*"     "|"
 9+            "\\[[^]]+\\]\\([^\\)]+\\)"  "|"
10+            "https?:/" "/[^[:space:]]+"
11+        ")");
12     int n = 0;
13 
14     p = sm;
15@@ -135,6 +140,16 @@ static xs_str *format_line(const char *line, xs_list **attach)
16                     s = xs_str_cat(s, s1);
17                 }
18             }
19+            else
20+            if (*v == '[') {
21+                /* markdown-like links [label](url) */
22+                xs *w    = xs_strip_chars_i(xs_dup(v), "[)");
23+                xs *l    = xs_split(w, "](");
24+                xs *link = xs_fmt("<a href=\"%s\">%s</a>",
25+                            xs_list_get(l, 1), xs_list_get(l, 0));
26+
27+                s = xs_str_cat(s, link);
28+            }
29             else
30                 s = xs_str_cat(s, v);
31         }