Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erwinmatijsen/django-markdownify
Markdown template filter for Django
https://github.com/erwinmatijsen/django-markdownify
Last synced: 16 days ago
JSON representation
Markdown template filter for Django
- Host: GitHub
- URL: https://github.com/erwinmatijsen/django-markdownify
- Owner: erwinmatijsen
- License: mit
- Created: 2016-01-19T17:43:50.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T07:55:23.000Z (4 months ago)
- Last Synced: 2024-10-01T16:20:54.573Z (about 1 month ago)
- Language: Python
- Size: 92.8 KB
- Stars: 118
- Watchers: 2
- Forks: 24
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-django-cn - django-markdownify, star:35 - Django Markdownify 模板过滤器用于将 Markdown 文本转成 HTML。 (表单)
README
# Django Markdownify - A Django Markdown filter
![PyPi Downloads](https://img.shields.io/pypi/dm/django-markdownify)
![License](https://img.shields.io/pypi/l/django-markdownify?color=brightgreen)
[![Documentation Status](https://readthedocs.org/projects/django-markdownify/badge/?version=latest)](https://django-markdownify.readthedocs.io/en/latest/?badge=latest)
![Version](https://img.shields.io/pypi/v/django-markdownify)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](http://django-markdownify.readthedocs.io/en/latest/) or check out the package on [pypi](https://pypi.python.org/pypi/django-markdownify).
> [!WARNING]
> The [old settings](https://django-markdownify.readthedocs.io/en/latest/settings-old.html#oldsettings) are removed in release 0.9.4! Please update to the [new settings](https://django-markdownify.readthedocs.io/en/latest/settings.html) 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:
```html
Some test link
```The filter is a wrapper around [Markdown](https://pypi.python.org/pypi/Markdown) and
[Bleach](http://pythonhosted.org/bleach/index.html) and as such supports their settings.
It is possible to define multiple settings for multiple usecases.For example:
```python
# settings.pyMARKDOWNIFY = {
"default": {
"WHITELIST_TAGS": ["a", "p", "h1", ]
},"alternative": {
"WHITELIST_TAGS": ["a", "p", ],
"MARKDOWN_EXTENSIONS": ["markdown.extensions.fenced_code", ]
}
}
```And in your templates:
```html
{{ mytext|markdownify }}
{{ mytext|markdownify:"alternative" }}
```## Documentation
Read the full documentation on [Read the docs](https://django-markdownify.readthedocs.io/en/latest/).## Credits
This filter is a slightly richer and packaged version of the snippet: [using-markdown-django-17](http://www.jw.pe/blog/post/using-markdown-django-17/).