Skip to main content

Documentation Utilities (Docutils, reStructuredText) for django.

Project description

django-docutils · Python Package License

django-docutils, docutils (reStructuredText) support for Django

Quickstart

Install django-docutils:

$ pip install django-docutils

Template filter

If you want to use the template filter, add it to your INSTALLED_APPS in your settings file:

INSTALLED_APPS = [ # ... your default apps,
    'django_docutils'
]

Then in your template:

{% load django_docutils %}
{% filter restructuredtext %}
# hey
# how's it going
A. hows
B. it

C. going
D. today

**hi**
*hi*
{% endfilter %}

Template engine (class-based view)

You can also use a class-based view to render restructuredtext.

If you want to use reStructuredText as a django template engine, INSTALLED_APPS isn't required, instead you add this to your TEMPLATES variable in your settings:

TEMPLATES = [ # .. your default engines
{
    'NAME': 'docutils',
    'BACKEND': 'django_docutils.engines.Docutils',
    'DIRS': [],
    'APP_DIRS': True,
}]

Now django will be able to scan for .rst files and process them. In your view:

from django_docutils.views import DocutilsView

class HomeView(DocutilsView):
    template_name = 'base.html'
    rst_name = 'home.rst'

Settings

DJANGO_DOCUTILS_LIB_RST = {  # Optional, automatically maps roles, directives and transformers
    'docutils': {
        'raw_enabled': True,
        'strip_comments': True,
        'initial_header_level': 2,
    },
    'roles': {
        'local': {
            'gh': 'django_docutils.lib.roles.github.github_role',
            'twitter': 'django_docutils.lib.roles.twitter.twitter_role',
            'email': 'django_docutils.lib.roles.email.email_role',
        }
    },
    'font_awesome': {  # Transformer to inject <em class="<class>"></em>
        'url_patterns': {
            r'.*github.com.*': 'fab fa-github',
            r'.*twitter.com.*': 'fab fa-twitter',
            r'.*news.ycombinator.com*': 'fab fa-hacker-news',
            r'.*leanpub.com.*': 'fab fa-leanpub',
            r'.*python.org.*': 'fab fa-python',
            r'.*pypi.org.*': 'fab fa-python',
            r'.*djangoproject.com.*': 'fab fa-python',
            r'.*wikipedia.org.*': 'fab fa-wikipedia',
            r'((rtfd|readthedocs).)*$': 'fab fa-books',
            r'^mailto:.*': 'fas fa-envelope',
            r'((?!mywebsite.com|localhost).)*$': 'fas fa-external-link',
        }
    },
}

DJANGO_DOCUTILS_LIB_TEXT = {  # Optional
    'uncapitalized_word_filters': ['project.my_module.my_capitalization_fn']
}

More information

  • Python 3.8+
  • Django 3.2+

Docs Build Status Code Coverage

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_docutils-0.13.5.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

django_docutils-0.13.5-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

Details for the file django_docutils-0.13.5.tar.gz.

File metadata

  • Download URL: django_docutils-0.13.5.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for django_docutils-0.13.5.tar.gz
Algorithm Hash digest
SHA256 a43e793f994bdd4fd5b47cca71b479cb478e3cdf204f617401c2e239ea90ebe4
MD5 83b2b8a98ea26ad18e62ee91d788fc70
BLAKE2b-256 2066b45ae99ca3f211a5e190763e7e702b09dc73e9d0a21efbb6f977d2b4023d

See more details on using hashes here.

Provenance

File details

Details for the file django_docutils-0.13.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_docutils-0.13.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf1a1e2e89472e1ff189397e83eb1cd3f3568fc3dd46d4af0d80093ff60bb47
MD5 89e3d9190d6f8b3eaa4c787e75d77558
BLAKE2b-256 6729dde58dee622efc90aecba241d6273ec6b1b19a60059d6764c9b00427b698

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page