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.5.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

django_markdownify-0.9.5-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_markdownify-0.9.5.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for django_markdownify-0.9.5.tar.gz
Algorithm Hash digest
SHA256 34c34eba4a797282a5c5bd97b13cec84d6a4c0673ad47ce1c1d000d74dd8d4ab
MD5 a7e23a24b4366d54cec62bbc4fe7ee82
BLAKE2b-256 6c333abb966e2b238af4c9a5d3ee38a7aa7e51b644b4b20bf8533b6fd1c1bf96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_markdownify-0.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4ae44e386c209453caf5e9ea1b74f64535985d338ad2d5ad5e7089cc94be86
MD5 175ea19a37702cc3411b93517b18b1e8
BLAKE2b-256 1b35c7a4bd957b279a8e7c808116bed399b73874ed3da78689993ee76f30d9f6

See more details on using hashes here.

Supported by

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