Attention! This snippet must be ignored, like zgoda pointed with reason: already exists this functionality in markup
contrib.
Explanations:
This template filter allows you to render easily a reStructuredText to HTML or another format it supports.
Setup:
Insert the snippet into an_app/templatetags/restutils.py.
Use in template:
{% load restutils %}
and use it as following:
{{ entry.content|rest:"html" }}
1 2 3 4 5 6 7 8 | from django.template import Library
from docutils.core import publish_parts
@register.filter
def rest(value, arg):
arg = arg or 'html'
parts = publish_parts(value, writer_name=arg)
return parts['html_body']
|
More like this
- Add custom fields to the built-in Group model by jmoppel 1 month, 2 weeks ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 4 months, 4 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 5 months, 1 week ago
- Browser-native date input field by kytta 6 months, 3 weeks ago
- Generate and render HTML Table by LLyaudet 7 months ago
Comments
Why would one need to reinvent the wheel? There is already ReST filter in
markup
contrib library.#
hummm... it's truth, I not knew this :/ thanks :)
#
Please login first before commenting.