Skip to main content

Markdown template filter for Django.

Project description

Django Markdownify - A Django Markdown filter

PyPi Downloads License Documentation Status Version

Django Markdownify is a template filter to convert Markdown to HTML in Django. Markdown is converted to HTML and sanitized.

Read the full documentation on Read the docs or check out the package on pypi.

[!WARNING]
The old settings are removed in release 0.9.4! Please update to the new settings as soon as possible.

Usage

Load the tag inside your template:

{% load markdownify %}

Then you can change markdown to html as follows:

{{ 'text'|markdownify }}

or

{{ somevariable|markdownify }}

Example

{% load markdownify %}
{{'Some *test* [link](#)'|markdownify }}

Is transformed to:

<p>
  Some <em>test</em> <a href="#">link</a>
</p>

The filter is a wrapper around Markdown and Bleach and as such supports their settings. It is possible to define multiple settings for multiple usecases.

For example:

# settings.py

MARKDOWNIFY = {
  "default": {
     "WHITELIST_TAGS": ["a", "p", "h1", ]
  },

  "alternative": {
     "WHITELIST_TAGS": ["a", "p", ],
     "MARKDOWN_EXTENSIONS": ["markdown.extensions.fenced_code", ]
  }
}

And in your templates:

<!-- page1.html -->
{{ mytext|markdownify }} <!-- Uses your default settings -->

<!-- page2.html -->
{{ mytext|markdownify:"alternative" }} <!-- Uses your alternative settings -->

Documentation

Read the full documentation on Read the docs.

Credits

This filter is a slightly richer and packaged version of the snippet: using-markdown-django-17.

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_markdownify-0.9.6.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_markdownify-0.9.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file django_markdownify-0.9.6.tar.gz.

File metadata

  • Download URL: django_markdownify-0.9.6.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for django_markdownify-0.9.6.tar.gz
Algorithm Hash digest
SHA256 edcf47b2026d55a8439049d35c8b54e11066a4856c4fad1060e139cb3d2eee52
MD5 d62ff20f600c33e379e40273a5ba9715
BLAKE2b-256 4565f3630c4cc20511b9c9f222a9005373a7fbd303e3233befd7a163200e631a

See more details on using hashes here.

File details

Details for the file django_markdownify-0.9.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_markdownify-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9863b2bfa6d159ad1423dc93bf0d6eadc6413776de304049aa9fcfa5edd2ce1c
MD5 571518de411e03995ad324dac0fcc104
BLAKE2b-256 67e1fafee8ffd7b5a1c4fd5eaf303a00c8bbbf38a90eae940823146c38b9a188

See more details on using hashes here.

Supported by

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