
django-rstify
django-rstify - A restructured text filter for django templates
django-rstify is a set of template filters to provide easy conversion from restructured text to HTML. Besides this basic functionality this application allows you to highlight sourcecode snippets inside your text using the pygments library.
Note: Django already provides a simple restructured text filter. If you don't need the extras in this application, I recommend to use the core version.
Download
The main repository of this app is located on Github. You can easily checkout the latest version using git:
git clone git://github.com/bartTC/django-rstify.git
or download this app as a .tar.gz file. See Links on the right side for download links.
How to use it in templates
To convert a restructured text from an object to HTML simply apply the rstify filter on it:
``` {% load rstify_tags %}
{{ entry.content|rstify }} ```
If you want to convert inline content, use the filter templatetag around:
``` {% load rstify_tags %}
{% filter rstify %} This is some restructured text. {% endfilter %} ```
How to use it in sourcecode
Applying this filter inside your code is easy:
```
from rstify import rstify
print rstify('This is restructured text.')
This is restructured text.
```
Initial Header Level
By default the initial heading in your restructured text becomes a in HTML:
>>> header = '''
... ================
... This is a Header
... ================
... '''
>>> print rstify(header)
<div class="section">
<h1><a id="this-is-a-header" name="this-is-a-header">This is a Header</a></h1>
</div>
You can override this by setting the initial_header_level to an integer from 1 to 6:
>>> print rstify(header, initial_header_level=3)
<div class="section">
<h3><a id="this-is-a-header" name="this-is-a-header">This is a Header</a></h3>
</div>
In your template just set this as the first option of the rstify filter:
{{ entry.content|rstify:"3" }}
Syntax Highlighting
django-rstify provides syntax highlighting using the pygments library. To highlight parts of your restructured text, simply put it in a sourcecode directive:
Here is some text. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Integer porttitor nulla sed dui. Aenean lorem mi, tincidunt et, porttitor
nec, condimentum venenatis, felis. Maecenas ornare blandit leo.
.. sourcecode:: python
def foo(bar):
return bar*2
Continue with text. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Integer porttitor nulla sed dui. Aenean lorem mi, tincidunt et, porttitor nec,
condimentum venenatis, felis. Maecenas ornare blandit leo.
Pygments provides a bunch of highlighters (also called lexer), just replace python
with a lexer of your choice. Here is a complete set of http://pygments.org/docs/lexers/'>available lexers. Read http://pygments.org/docs/styles/'>pygments styles how to colorize the output using css.
Project Information
- License: New BSD License
- 4 stars
- svn-based source control
Labels:
django
rst
restructuredtext
markup
template
templatetag
filter