The idea is the following. I send some text to jinja2 using tags similar to stackoverflow's. How do I tell jinja2 to treat them as a markup containing text and to generate bold, italic and so on text in html?
Thank you.
I'm used to django-markdown, so I think using a filter is a nice way to accomplish this:
<div class="content">{{ article.body|rst }}</div>
I'm not aware if such filter exists for jinja2 but it should be very easy to write. I guess something in the line of this (untested code):
from docutils.core import publish_parts
import jinja2
def rst_filter(s):
return jinja2.Markup(publish_parts(source=s, writer_name='html')['body'])
environment.filters['rst'] = rst_filter
You should be able to do this:
from docutils.core import publish_string
import jinja2
html = publish_string(source=text, writer_name='html')
node = jinja2.Markup(html)
Where node
is the Jinja 2 node to actually include in your scope.
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