format.c: Allow several tags

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2023-07-23 14:55:06 +07:00
parent 11aafbc46f
commit 5672fe2cc6

View file

@ -139,6 +139,16 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
else else
ss = xs_strip_i(format_line(v, attach)); ss = xs_strip_i(format_line(v, attach));
if (xs_startswith(ss, "---")) {
/* delete the --- */
ss = xs_strip_i(xs_crop_i(ss, 3, 0));
s = xs_str_cat(s, "<hr>");
s = xs_str_cat(s, ss);
continue;
}
if (xs_startswith(ss, ">")) { if (xs_startswith(ss, ">")) {
/* delete the > and subsequent spaces */ /* delete the > and subsequent spaces */
ss = xs_strip_i(xs_crop_i(ss, 1, 0)); ss = xs_strip_i(xs_crop_i(ss, 1, 0));
@ -186,8 +196,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
const char *valid_tags[] = { const char *valid_tags[] = {
"a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "small",
"span", "i", "b", "u", "pre", "code", "em", "strong", NULL "span", "i", "b", "u", "pre", "code", "em", "strong", "hr", "img", "del", NULL
}; };
xs_str *sanitize(const char *content) xs_str *sanitize(const char *content)
@ -219,7 +229,7 @@ xs_str *sanitize(const char *content)
if (valid_tags[i]) { if (valid_tags[i]) {
/* accepted tag: rebuild it with only the accepted elements */ /* accepted tag: rebuild it with only the accepted elements */
xs *el = xs_regex_match(v, "(href|rel|class|target)=\"[^\"]*\""); xs *el = xs_regex_match(v, "(src|href|rel|class|target)=\"[^\"]*\"");
xs *s3 = xs_join(el, " "); xs *s3 = xs_join(el, " ");
s2 = xs_fmt("<%s%s%s%s>", s2 = xs_fmt("<%s%s%s%s>",