snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 8e0ccc6d76af26c83e5adebfaa18aef364e59975
parent 37b6c7926e895aedb79b39cd2e9c788c26a7db28
Author: default <nobody@localhost>
Date:   Sun, 26 May 2024 09:27:36 +0200

Added markdown-like links.

Diffstat:
Mformat.c | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/format.c b/format.c @@ -87,7 +87,12 @@ static xs_str *format_line(const char *line, xs_list **attach) /* split by markup */ xs *sm = xs_regex_split(line, - "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)"); + "(" + "`[^`]+`" "|" + "\\*\\*?[^\\*]+\\*?\\*" "|" + "\\[[^]]+\\]\\([^\\)]+\\)" "|" + "https?:/" "/[^[:space:]]+" + ")"); int n = 0; p = sm; @@ -136,6 +141,16 @@ static xs_str *format_line(const char *line, xs_list **attach) } } else + if (*v == '[') { + /* markdown-like links [label](url) */ + xs *w = xs_strip_chars_i(xs_dup(v), "[)"); + xs *l = xs_split(w, "]("); + xs *link = xs_fmt("<a href=\"%s\">%s</a>", + xs_list_get(l, 1), xs_list_get(l, 0)); + + s = xs_str_cat(s, link); + } + else s = xs_str_cat(s, v); } else