Format body better with \n and .md link html conversion
This commit is contained in:
parent
dc5220fa05
commit
e83f646dd8
|
|
@ -308,6 +308,7 @@ def get_posts_from_select(cursor, select, binds):
|
||||||
add_media_html_to_posts(posts)
|
add_media_html_to_posts(posts)
|
||||||
add_subreddits_to_posts(posts)
|
add_subreddits_to_posts(posts)
|
||||||
add_age_to_posts(posts)
|
add_age_to_posts(posts)
|
||||||
|
reformat_body(posts)
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
def add_media_html_to_posts(posts):
|
def add_media_html_to_posts(posts):
|
||||||
|
|
@ -339,6 +340,12 @@ def add_age_to_posts(posts):
|
||||||
else:
|
else:
|
||||||
post["age"] = str(int(diff//(3600*24)))+'d'
|
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", "<br>")
|
||||||
|
post["body"] = re.sub(r"\[(.*?)\]\((.*?)\)", r'<b><a href="\2" style="white-space: nowrap;" class="no-style-link">\1</a></b>', post["body"])
|
||||||
|
|
||||||
|
|
||||||
def get_media_html(file, priority=False):
|
def get_media_html(file, priority=False):
|
||||||
if file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png') or file.endswith('.gif'):
|
if file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png') or file.endswith('.gif'):
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if post.body %}
|
{% if post.body %}
|
||||||
<div class="text-content" onclick="expand(this)">
|
<div class="text-content" onclick="expand(this)">
|
||||||
{{ post.body }}
|
{{ post.body|safe }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="button-wrapper">
|
<span class="button-wrapper">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue