The classic task is to display the list of blog-posts, including a short summary of each post.
As I have seen on the web, the most common approach is to truncate the content of the original blog post.
So my post_list.html
template looks like this:
{% load custom_markdown %}
<div class="col-sm-12">
<p>
<small>
{{ post.text | custom_markdown | truncatechars:160 }}
</small>
</p>
</div>
If I truncate markdown sometimes the html tags do not get closed properly - the end tag gets truncated - and the whole html page gets all messed-up.
Is there an intelligent way to truncate or do I need to write my own function?
PS The closest I got was this stackoverflow post: how to truncate markdown in Ruby/Rails.
You can use the truncatechars_html
tag.
{{ post.text | custom_markdown | truncatechars_html:160 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With