djangocms-markdown
A markdown content plugin and model field for django CMS. Write content in Markdown using an integrated editor and have it rendered as HTML on your site.
Attention: Version 0.3.2 is from a different project by the great Nicolas Noé. This project is an entirely different rewrite with different goals.
Features
- MDText CMS plugin — add markdown content to any django CMS placeholder
- MarkdownField — a model field for storing markdown in your own models,
with a
.renderedproperty that returns HTML - EasyMDE editor — a full-featured markdown editor with toolbar, preview, and side-by-side mode in the admin and CMS plugin forms
- Dynamic object references — link to any Django object with
[text](ref:app.model:pk)syntax; URLs are resolved at render time so they stay up to date. When an object is deleted, the link is replaced with plain text. - Inline reference picker — when the cursor is inside a markdown link, a select2 autocomplete popup appears above the link, allowing you to search and select internal pages or objects. Requires djangocms-link or a custom autocomplete endpoint. If the link text is empty it is filled with the selected object's name.
- Template filter —
{{ value|render_markdown }}for rendering markdown anywhere in templates - Configurable rendering — uses Python-Markdown with sensible defaults (tables, fenced code, syntax highlighting, TOC, and more)
- Extension hooks — other django CMS apps can contribute Python-Markdown extensions together with their page assets and editor preview (see Extension hooks)
Installation
pip install djangocms-markdown
Add djangocms_markdown to your INSTALLED_APPS:
INSTALLED_APPS = [
...,
"djangocms_markdown",
]
Run migrations:
python manage.py migrate djangocms_markdown
Usage
CMS plugin
After installation the Markdown plugin is available in the plugin picker under the Generic module. Add it to any placeholder and write markdown in the editor. The content is rendered to HTML on save and displayed on the page.
MarkdownField (models)
Use MarkdownField in your own models just like a TextField:
from django.db import models
from djangocms_markdown.fields import MarkdownField
class Article(models.Model):
body = MarkdownField()
The field stores raw markdown. Access the rendered HTML through the .rendered
property:
article = Article.objects.get(pk=1)
str(article.body) # raw markdown
article.body.rendered # rendered HTML (marked safe)
In admin forms the field automatically uses the EasyMDE markdown editor.
Template filter
{% load djangocms_markdown_tags %}
{{ article.body|render_markdown }}
Configuration
All settings are optional.
-
DJANGOCMS_MARKDOWN_EXTENSIONS— list of Python-Markdown extensions to enable. Default:DJANGOCMS_MARKDOWN_EXTENSIONS = [ "markdown.extensions.extra", "markdown.extensions.codehilite", "markdown.extensions.toc", "markdown.extensions.sane_lists", ]
-
DJANGOCMS_MARKDOWN_EXTENSION_CONFIGS— dict of extension-specific configuration. Default:DJANGOCMS_MARKDOWN_EXTENSION_CONFIGS = { "markdown.extensions.codehilite": { "css_class": "highlight", "guess_lang": False, }, }
-
DJANGOCMS_MARKDOWN_PLUGIN_NAME— display name of the CMS plugin. Default:"Markdown" -
DJANGOCMS_MARKDOWN_PLUGIN_MODULE_NAME— module name the plugin appears under in the plugin picker. Default:"Generic" -
DJANGOCMS_MARKDOWN_TABLE_CLASS— CSS class(es) added to every<table>tag in rendered HTML. Useful for Bootstrap ("table") or other CSS frameworks. Set to""to disable. Default:"table" -
DJANGOCMS_MARKDOWN_EASYMDE_CDN_BASE— CDN base URL for loading the EasyMDE editor. Set to""to serve from your own static files instead. Default:"https://cdn.jsdelivr.net/npm/easymde@2.21.0/dist"
Rendered HTML is sanitized with nh3 using the same settings as djangocms-text:
TEXT_HTML_SANITIZE— set toFalseto disable sanitization (defaultTrue)TEXT_ADDITIONAL_TAGS— extra HTML tags to allowTEXT_ADDITIONAL_ATTRIBUTES— extra attributes to allow per tagTEXT_ADDITIONAL_PROTOCOLS— extra URL schemes to allow
Extension hooks
Other django CMS packages can extend djangocms-markdown with their own
Python-Markdown extensions,
together with the frontend assets the generated HTML needs and a matching
editor preview. A project only needs to add such a package to
INSTALLED_APPS.
django CMS 3.11: registration uses django CMS's app registration (
cms_config.py), which exists in django CMS 4.1 and later. django CMS 3.11 never loadscms_config.py, so none of the hooks below are available there;DJANGOCMS_MARKDOWN_EXTENSIONSandDJANGOCMS_MARKDOWN_EXTENSION_CONFIGSremain the only way to add extensions.
Registering from cms_config.py
An app opts in from its own cms_config.py. All attributes except
djangocms_markdown_enabled are optional:
# my_app/cms_config.py
from cms.app_base import CMSAppConfig
from django import forms
class MyAppConfig(CMSAppConfig):
djangocms_markdown_enabled = True
djangocms_markdown_extensions = ["my_app.markdown"]
djangocms_markdown_extension_configs = {"my_app.markdown": {"css_class": "spoiler"}}
djangocms_markdown_assets = {
"css": ['<link rel="stylesheet" href="/static/my_app/spoiler.css">'],
"js": [
'<script defer src="/static/my_app/spoiler.js" data-animate="true"></script>'
],
}
djangocms_markdown_editor_media = forms.Media(js=["my_app/spoiler_preview.js"])
| Attribute | Value |
|---|---|
djangocms_markdown_extensions |
List of Python-Markdown extension names, e.g. "my_app.markdown" (a module with makeExtension()) or "my_app.markdown:SpoilerExtension". |
djangocms_markdown_extension_configs |
Dict mapping extension names to their config dicts. |
djangocms_markdown_assets |
Page assets, see Page assets. |
djangocms_markdown_editor_media |
Editor media, see Editor media and preview. |
Invalid declarations raise ImproperlyConfigured at startup, naming the app.
This includes extensions that cannot be loaded, such as a misspelled name.
- Order: the effective extension list is
DJANGOCMS_MARKDOWN_EXTENSIONSfirst, followed by contributed extensions inINSTALLED_APPSorder, without duplicates. - Configs: extension configs are merged option by option. Options set in
the project's
DJANGOCMS_MARKDOWN_EXTENSION_CONFIGS(or its default) win over contributed ones; if several apps configure the same option, the app listed first inINSTALLED_APPSwins. - Names only: extensions are contributed by name, not as
markdown.Extensioninstances. Python-Markdown then creates fresh instances for every render, so extension state (collected footnotes, for example) cannot carry over from one render or request to another. Usedjangocms_markdown_extension_configsto configure them. - Opting out: an app decides for itself whether to contribute, e.g. by
setting
djangocms_markdown_enabled = getattr(settings, "MY_APP_MARKDOWN", True). - Callables: where a callable is accepted it is called as a plain function
(
assets(html),editor_media()); a function assigned to the attribute is not bound to the config instance. - Sanitizer: contributed extensions run before the HTML sanitizer. If an
extension generates tags or attributes the sanitizer removes, the project
has to allow them with the
TEXT_ADDITIONAL_*settings. - Stored HTML: the CMS plugin renders markdown when it is saved. Existing plugins pick up newly added extensions when they are saved again.
Page assets
djangocms_markdown_assets tells djangocms-markdown what to add to the page
when rendered markdown is shown. It is either
-
a dict mapping sekizai block names to lists of HTML snippets (see above). Snippets are arbitrary HTML, so they can carry attributes such as
deferordata-*; or -
a callable taking the rendered HTML and returning such a dict, or
Noneif this content needs nothing:from django.templatetags.static import static def spoiler_assets(html): if 'class="spoiler"' not in html: return None return {"js": [f'<script defer src="{static("my_app/spoiler.js")}"></script>']} class MyAppConfig(CMSAppConfig): djangocms_markdown_enabled = True djangocms_markdown_assets = spoiler_assets
Callables are evaluated when a page is rendered, never at import time, so
static()is safe to use.
The CMS plugin adds the snippets to the sekizai blocks each time it is
rendered on a page (they are not part of the stored HTML). sekizai drops
identical snippets, so each asset is loaded once no matter how many markdown
plugins a page has. The page template needs the usual
{% render_block "css" %} and {% render_block "js" %}; without them (or
without sekizai's context processor) the page renders normally, just without
the assets.
For MarkdownField and the render_markdown filter in your own
templates, pass the rendered HTML to the markdown_assets tag. It outputs
nothing and adds the assets to the sekizai blocks:
{% load djangocms_markdown_tags %}
{% with html=article.body.rendered %}
{{ html }}
{% markdown_assets html %}
{% endwith %}
In Python, djangocms_markdown.rendering.get_assets(html) returns the merged
contributions of all apps as a {block name: [snippets]} dict.
Editor media and preview
djangocms_markdown_editor_media is a django.forms.Media instance, or a
callable returning one. It is added to the media of the markdown editor widget
after the widget's own files — in the plugin form and in any admin form using
MarkdownField. Use it to load styles and scripts for the editor preview.
The editor preview is rendered in the browser and does not know about server-side extensions. Scripts can register preview processors in a global array; this works regardless of script load order:
// my_app/static/my_app/spoiler_preview.js
window.djangocmsMarkdownPreview = window.djangocmsMarkdownPreview || [];
window.djangocmsMarkdownPreview.push({
// Markdown source in, markdown source out. Runs before the preview is
// rendered, e.g. to protect a span from markdown with a placeholder.
before: function (text) {
return text.replace(/\|\|(.+?)\|\|/g, "<span class=\"spoiler\">$1</span>");
},
// Receives a detached element holding the rendered preview and may change
// it. The element's innerHTML is what the preview shows.
after: function (element) {
element.querySelectorAll(".spoiler").forEach(function (spoiler) {
spoiler.title = "Spoiler";
});
},
});
Both functions are optional. Processors run in registration order, for "preview" as well as "side-by-side". An exception in a processor is logged to the browser console and does not affect the preview or other processors.
Minimal example app
my_app/
├── cms_config.py # see "Registering from cms_config.py"
├── markdown.py # the Python-Markdown extension
└── static/my_app/
├── spoiler.css, spoiler.js # page assets
└── spoiler_preview.js # editor preview processor
# my_app/markdown.py — turns ||text|| into <span class="spoiler">text</span>
from markdown.extensions import Extension
from markdown.inlinepatterns import SimpleTagInlineProcessor
class SpoilerProcessor(SimpleTagInlineProcessor):
def __init__(self, pattern, css_class):
super().__init__(pattern, "span")
self.css_class = css_class
def handleMatch(self, m, data):
el, start, end = super().handleMatch(m, data)
el.set("class", self.css_class)
return el, start, end
class SpoilerExtension(Extension):
def __init__(self, **kwargs):
self.config = {"css_class": ["spoiler", "CSS class of the span"]}
super().__init__(**kwargs)
def extendMarkdown(self, md):
md.inlinePatterns.register(
SpoilerProcessor(r"()\|\|(.+?)\|\|", self.getConfig("css_class")),
"spoiler",
175,
)
def makeExtension(**kwargs):
return SpoilerExtension(**kwargs)
Contributing
git clone https://github.com/fsbraun/djangocms-markdown.git
cd djangocms-markdown
python -m venv .venv
source .venv/bin/activate
pip install -e ".[test]"
pytest
License
BSD-3-Clause
Metadata
Release files for djangocms-markdown 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| djangocms_markdown-1.1.0.tar.gz | 45.0 kB | With provenance | Details for djangocms_markdown-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| djangocms_markdown-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for djangocms_markdown-1.1.0-py3-none-any.whl |
Total release size: 75.3 kB
Release files / djangocms_markdown-1.1.0.tar.gz
| Download URL | djangocms_markdown-1.1.0.tar.gz |
|---|---|
| Size | 45.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3181e2314319ef30521cf552c96b23f4ef9fdf04927c3a30b2b4f67efea93b71
|
|
BLAKE2b-256 checksum How to use checksums |
eec7a803b599f965d7bef12472e50777fa70b5826fb79a9e7953e1635334a1fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / djangocms_markdown-1.1.0-py3-none-any.whl
| Download URL | djangocms_markdown-1.1.0-py3-none-any.whl |
|---|---|
| Size | 30.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1bd2c9d3fdc0c5b866d07c9ece7a06798652547e43f434e6f8db20ab43856d4
|
|
BLAKE2b-256 checksum How to use checksums |
49a5d1b1e9120675963eaa7e5f27705ae86cae7ef8bef935f1dd4008bd3c8209
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for djangocms-markdown 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for djangocms_markdown-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.