diff options
author | default <nobody@localhost> | 2022-09-27 10:51:50 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-27 10:51:57 +0200 |
commit | 4f3b70d9979b22cfc1a789b14602a12ee5c896c7 (patch) | |
tree | 289541acdb3fa7b38783a2e3ce9f10047ea05e05 /html.c | |
parent | 25258ed379a16a72778ed45cca2a297483d002e6 (diff) |
More work in not_really_markdown().
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 60 |
1 files changed, 58 insertions, 2 deletions
@@ -4,6 +4,7 @@ #include "xs.h" #include "xs_io.h" #include "xs_json.h" +#include "xs_regex.h" #include "snac.h" @@ -15,10 +16,65 @@ d_char *not_really_markdown(char *content, d_char **f_content) int in_blq = 0; xs *list; char *p, *v; + xs *wrk = xs_dup(content); - s = xs_str_new(NULL); + /* global changes */ + { + /* backticks */ + xs *ml = xs_regex_matchall(wrk, "`[^`]+`"); + p = ml; + + while (xs_list_iter(&p, &v)) { + xs *s1 = xs_crop(xs_dup(v), 1, -1); + xs *s2 = xs_fmt("<code>%s</code>", s1); + + wrk = xs_replace_i(wrk, v, s2); + } + } + + { + /* double asterisks */ + xs *ml = xs_regex_matchall(wrk, "\\*\\*[^\\*]+\\*\\*"); + p = ml; + + while (xs_list_iter(&p, &v)) { + xs *s1 = xs_crop(xs_dup(v), 2, -2); + xs *s2 = xs_fmt("<b>%s</b>", s1); + + wrk = xs_replace_i(wrk, v, s2); + } + } + + { + /* single asterisks */ + xs *ml = xs_regex_matchall(wrk, "\\*[^\\*]+\\*"); + p = ml; + + while (xs_list_iter(&p, &v)) { + xs *s1 = xs_crop(xs_dup(v), 1, -1); + xs *s2 = xs_fmt("<i>%s</i>", s1); - p = list = xs_split(content, "\n"); + wrk = xs_replace_i(wrk, v, s2); + } + } + + { + /* urls */ + xs *ml = xs_regex_matchall(wrk, "https?:/" "/[^ ]+"); + p = ml; + + while (xs_list_iter(&p, &v)) { + xs *s2 = xs_fmt("<a href=\"%s\">%s</a>", v, v); + + wrk = xs_replace_i(wrk, v, s2); + } + } + + /* now work on lines */ + + p = list = xs_split(wrk, "\n"); + + s = xs_str_new(NULL); while (xs_list_iter(&p, &v)) { xs *ss = xs_strip(xs_dup(v)); |