Merge pull request 'Allow several tags & fix video element width, and more.' (#74) from yonle/snac2:master into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/74
This commit is contained in:
grunfink 2023-07-24 10:49:18 +00:00
commit ad4fccd60d
2 changed files with 27 additions and 8 deletions

View file

@ -1,5 +1,6 @@
body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em } body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em; word-wrap: break-word; }
img { max-width: 100% } pre { overflow-x: scroll; }
.snac-embedded-video, img { max-width: 100% }
.snac-origin { font-size: 85% } .snac-origin { font-size: 85% }
.snac-score { float: right; font-size: 85% } .snac-score { float: right; font-size: 85% }
.snac-top-user { text-align: center; padding-bottom: 2em } .snac-top-user { text-align: center; padding-bottom: 2em }

View file

@ -56,7 +56,8 @@ static xs_str *format_line(const char *line, xs_list **attach)
/* markup */ /* markup */
if (xs_startswith(v, "`")) { if (xs_startswith(v, "`")) {
xs *s1 = xs_crop_i(xs_dup(v), 1, -1); xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
xs *s2 = xs_fmt("<code>%s</code>", s1); xs *e1 = encode_html(s1);
xs *s2 = xs_fmt("<code>%s</code>", e1);
s = xs_str_cat(s, s2); s = xs_str_cat(s, s2);
} }
else else
@ -134,11 +135,28 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
continue; continue;
} }
if (in_pre) if (in_pre) {
ss = xs_dup(v); // Encode all HTML characters when we're in pre element until we are out.
ss = encode_html(xs_dup(v));
s = xs_str_cat(s, ss);
s = xs_str_cat(s, "<br>");
continue;
}
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 +204,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 +237,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>",