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.
Installation
There are several ways to install this application:
Checkout the latest version from my git repository:
git clone git://github.com/bartTC/django-rstify.git
Then either put the directory rstify into your pythonpath or switch to django-rstify and do python setup.py install.
Install this application using easy_install:
easy_install django-rstify
Finally, put rstify into your INSTALLED_APPS setting in your django project.
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*.')
<p>This is <em>restructured text</em>.</p>
Initial Header Level
By default the initial heading in your restructured text becomes a <h1> 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 available lexers. Read pygments styles how to colorize the output using css.
License
This application is licensed under the New BSD License. See LICENSE for details. django-rstify comes bundled with a pygments directive which is released under BSD License. See rstify/pygments_directive.py for details.
Metadata
Release files for django-rstify 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-rstify-0.2.tar.gz | 5.2 kB | Without provenance | Details for django-rstify-0.2.tar.gz |
Release files / django-rstify-0.2.tar.gz
| Download URL | django-rstify-0.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8121165b9c01a19e5aa6d005b92c09d34e32a89a5bdc00cb0cca00f90bbba9f3
|
|
BLAKE2b-256 checksum How to use checksums |
ad6db87198ebd9b89d78945a94551f43866476188c9e0b66ae39391c9abe7d6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-rstify 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.