Login

A simple rest template filter

Author:
marinho
Posted:
November 15, 2007
Language:
Python
Version:
.96
Tags:
rest template-filters
Score:
-1 (after 3 ratings)

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

  1. Template filters utils by marinho 7 years, 5 months ago
  2. Date/time util template filters by marinho 7 years, 5 months ago
  3. django form template with bootstrap by youyongsong 3 months ago
  4. Add delete buttons to admin changelist by kylefox 7 years, 11 months ago
  5. RESTful class dispatch by Phoenix 5 years, 10 months ago

Comments

zgoda (on November 15, 2007):

Why would one need to reinvent the wheel? There is already ReST filter in markup contrib library.

#

marinho (on November 16, 2007):

hummm... it's truth, I not knew this :/ thanks :)

#

Please login first before commenting.