Skip to main content

Markdown template filter for Django.

Project description

Django Markdownify - A Django Markdown filter

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.

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.2.tar.gz (7.9 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.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file django-markdownify-0.9.2.tar.gz.

File metadata

  • Download URL: django-markdownify-0.9.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for django-markdownify-0.9.2.tar.gz
Algorithm Hash digest
SHA256 6906d75197e9fc1c5faf1b68241e4abbf0dd00a627e75bfce6ee7e54b46d737f
MD5 f1388200d55a8c6c4e0402d800089a5c
BLAKE2b-256 4eedd1e63c9304b57052bca4d9d079384edcd8c857715c70b385310e1877f615

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_markdownify-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bc2b7e1c51c696b7c460eacb71d7fd94dadf6575897feae7ba49e155502a3ba
MD5 7aaa44153a72755bb217e266bd6475cc
BLAKE2b-256 e34e0589bbbc9e0f1a708e3581bf58c526bf3fa245f64bc7d1702999b74ed966

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