From e83f646dd814babdfcedb464de314e4fe438653a Mon Sep 17 00:00:00 2001 From: John Stephani Date: Sun, 28 Dec 2025 02:36:45 -0600 Subject: [PATCH] Format body better with \n and .md link html conversion --- app/app.py | 7 +++++++ app/templates/index.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index b9a7f64..5a57b64 100755 --- a/app/app.py +++ b/app/app.py @@ -308,6 +308,7 @@ def get_posts_from_select(cursor, select, binds): add_media_html_to_posts(posts) add_subreddits_to_posts(posts) add_age_to_posts(posts) + reformat_body(posts) return posts def add_media_html_to_posts(posts): @@ -339,6 +340,12 @@ def add_age_to_posts(posts): else: post["age"] = str(int(diff//(3600*24)))+'d' +def reformat_body(posts): + for post in posts: + if "body" in post and post["body"] is not None: + post["body"] = post["body"].rstrip().replace("\n", "
") + post["body"] = re.sub(r"\[(.*?)\]\((.*?)\)", r'\1', post["body"]) + def get_media_html(file, priority=False): if file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png') or file.endswith('.gif'): diff --git a/app/templates/index.html b/app/templates/index.html index b37ec6c..26b7c52 100755 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -243,7 +243,7 @@ {% endif %} {% if post.body %}
- {{ post.body }} + {{ post.body|safe }}
{% endif %}