From 11aafbc46f37b7c299a03a421a646cbcab8d5b79 Mon Sep 17 00:00:00 2001 From: Yonle Date: Fri, 21 Jul 2023 10:37:34 +0700 Subject: [PATCH 1/4] default css: Set max width for video attachment Signed-off-by: Yonle --- doc/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/style.css b/doc/style.css index 7b4839d..ffb14cd 100644 --- a/doc/style.css +++ b/doc/style.css @@ -1,5 +1,5 @@ body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em } -img { max-width: 100% } +.snac-embedded-video, img { max-width: 100% } .snac-origin { font-size: 85% } .snac-score { float: right; font-size: 85% } .snac-top-user { text-align: center; padding-bottom: 2em } From 5672fe2cc664680ef3fc1ead9da23576ad9b0f1e Mon Sep 17 00:00:00 2001 From: Yonle Date: Sun, 23 Jul 2023 14:55:06 +0700 Subject: [PATCH 2/4] format.c: Allow several tags Signed-off-by: Yonle --- format.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index 8c6c02a..0f5f368 100644 --- a/format.c +++ b/format.c @@ -139,6 +139,16 @@ xs_str *not_really_markdown(const char *content, xs_list **attach) else 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, "
"); + + s = xs_str_cat(s, ss); + + continue; + } + if (xs_startswith(ss, ">")) { /* delete the > and subsequent spaces */ 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[] = { - "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", - "span", "i", "b", "u", "pre", "code", "em", "strong", NULL + "a", "p", "br", "br/", "blockquote", "ul", "ol", "li", "cite", "small", + "span", "i", "b", "u", "pre", "code", "em", "strong", "hr", "img", "del", NULL }; xs_str *sanitize(const char *content) @@ -219,7 +229,7 @@ xs_str *sanitize(const char *content) if (valid_tags[i]) { /* 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, " "); s2 = xs_fmt("<%s%s%s%s>", From 7710ca76a04432c2dbd3a3f4c1f8e3f1f145e97f Mon Sep 17 00:00:00 2001 From: Yonle Date: Sun, 23 Jul 2023 20:20:15 +0700 Subject: [PATCH 3/4] format.c: Encode all HTML characters when we're in pre element until we are out. Signed-off-by: Yonle --- format.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index 0f5f368..fe71996 100644 --- a/format.c +++ b/format.c @@ -56,7 +56,8 @@ static xs_str *format_line(const char *line, xs_list **attach) /* markup */ if (xs_startswith(v, "`")) { xs *s1 = xs_crop_i(xs_dup(v), 1, -1); - xs *s2 = xs_fmt("%s", s1); + xs *e1 = encode_html(s1); + xs *s2 = xs_fmt("%s", e1); s = xs_str_cat(s, s2); } else @@ -134,8 +135,15 @@ xs_str *not_really_markdown(const char *content, xs_list **attach) continue; } - if (in_pre) - ss = xs_dup(v); + if (in_pre) { + // 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, "
"); + continue; + } + else ss = xs_strip_i(format_line(v, attach)); From ae1f0ac334e3e978183cf75feaa8bfc2f12df4c5 Mon Sep 17 00:00:00 2001 From: Yonle Date: Sun, 23 Jul 2023 20:31:39 +0700 Subject: [PATCH 4/4] default css: handle overflow text Signed-off-by: Yonle --- doc/style.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/style.css b/doc/style.css index ffb14cd..822860e 100644 --- a/doc/style.css +++ b/doc/style.css @@ -1,4 +1,5 @@ -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; } +pre { overflow-x: scroll; } .snac-embedded-video, img { max-width: 100% } .snac-origin { font-size: 85% } .snac-score { float: right; font-size: 85% }