From 768820cd4c4f8c81910b4bc35c35787d824dacd1 Mon Sep 17 00:00:00 2001 From: mikupls <93015331+mikupls@users.noreply.github.com> Date: Mon, 22 Nov 2021 00:17:52 +0100 Subject: [PATCH] Render markdown correctly in text post previews by using selftext_html. (#335) * Render markdown correctly in text post previews by using selftext_html. I was mistakenly under the impression that we somehow render markdown ourselves, but turns out we just take whatever HTML reddit gives us, and we also need to do this for text previews. Use CSS to limit the size of the previews instead of truncating in the template. Fix table CSS. * Fix post_body padding and trim post_previews Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com> --- src/utils.rs | 7 ++----- static/style.css | 5 +++-- templates/utils.html | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 2c74783..0bcad3c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -251,11 +251,8 @@ impl Post { // Determine the type of media along with the media URL let (post_type, media, gallery) = Media::parse(data).await; - // selftext is set for text posts when browsing a (sub)reddit. - // Do NOT use selftext_html, because we truncate this content - // in the template code, and using selftext_html might result - // in truncated html. - let mut body = rewrite_urls(&val(post, "selftext")); + // selftext_html is set for text posts when browsing. + let mut body = rewrite_urls(&val(post, "selftext_html")); if body == "" { body = rewrite_urls(&val(post, "body_html")) } diff --git a/static/style.css b/static/style.css index 2d3bf24..67a694d 100644 --- a/static/style.css +++ b/static/style.css @@ -838,14 +838,16 @@ a.search_subreddit:hover { .post_body { opacity: 0.9; font-weight: normal; - padding: 5px 15px; + padding: 5px 15px 5px 12px; grid-area: post_body; width: calc(100% - 30px); } +/* Used only for text post preview */ .post_preview { mask-image: linear-gradient(180deg,#000 60%,transparent); opacity: 0.8; + max-height: 250px; } .post_footer { @@ -1223,7 +1225,6 @@ input[type="submit"] { .md table { margin: 5px; - display: block; overflow-x: auto; } diff --git a/templates/utils.html b/templates/utils.html index e5ba8f8..efd591e 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -132,7 +132,7 @@