- Faster imports
- One new block
Quick start
Install
pip install dj-spellbook
It needs Python 3.12 or newer and Django 5.2 or newer. It brings three dependencies: Django, spellbook-engine and markdown-it-py. The engine's wheel is built for Linux x86-64; anywhere else pip builds it from source, which needs a Rust toolchain.
Add it to INSTALLED_APPS
INSTALLED_APPS = [
# your apps
"dj_spellbook",
]
That gives you the three built-in blocks and their stylesheet, and finds the blocks your own apps define.
Render a document
from dj_spellbook import spellbook_render
html = spellbook_render(document)
document is one markdown string. Here is one, and under it what dj-spellbook renders from it:
## Before you deploy
{~ alert type="warning" ~}
Take a backup **first**.
{~~}
Before you deploy
html comes back as:
<h2>Before you deploy</h2>
<aside class="spell-callout spell-callout--warning">
<div class="spell-callout-body">
<p>Take a backup <strong>first</strong>.</p>
</div>
</aside>
html is a SafeString, so a template prints it with {{ html }} and no |safe. Load the stylesheet in the same template:
{% load static %}
<link rel="stylesheet" href="{% static 'dj_spellbook/spellbook.css' %}">
The markdown renders as CommonMark plus tables, with one change: a new line inside a paragraph is a line break.
Use the built-in blocks
alert, card and accordion work as soon as the app is installed. One document can hold any number of them, with markdown inside each:
{~ card title="Release 2.4" footer="Shipped on a Tuesday" ~}
- Faster imports
- One new block
{~~}
{~ alert type="success" ~}
No migration needed.
{~~}
{~ accordion title="Upgrade notes" ~}
Run `pip install --upgrade` and restart.
{~~}
Upgrade notes
Run pip install --upgrade and restart.
Built-in blocks lists each one's arguments. Writing your own block shows how to add more.