Skip to content

Commit 9de2ba0

Browse files
committed
GH-10: Add support for base theme
1 parent 8564f69 commit 9de2ba0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/django_mermaid/templatetags/mermaid.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from django import template
24
from django.conf import settings
35
from django.templatetags.static import static
@@ -15,12 +17,14 @@ def mermaid(diagram=None, theme=None):
1517
"""Render a mermaid diagram.
1618
1719
:param diagram: The mermaid diagram definition
18-
:param theme: The mermaid theme to use (default, forest, dark, neutral). See https://mermaid.js.org/config/theming.
20+
:param theme: The mermaid theme to use (default, forest, dark, neutral, base). See https://mermaid.js.org/config/theming.
1921
"""
2022

2123
version = getattr(settings, "MERMAID_VERSION", DEFAULT_VERSION)
2224
theme = theme or getattr(settings, "MERMAID_THEME", DEFAULT_THEME)
25+
theme_variables = getattr(settings, "MERMAID_THEME_VARIABLES", {}) if theme == "base" else {}
2326

2427
mermaid_uri = static("mermaid/%s/mermaid.js" % version)
2528
html = "<div class=\"mermaid\">%s</div><script src=\"%s\"></script>" % (diagram or "", mermaid_uri)
26-
return html + "<script>mermaid.initialize({\"startOnLoad\": true, theme: \"%s\"});</script>" % theme
29+
init_properties = {"startOnLoad": True, "theme": theme, "themeVariables": theme_variables}
30+
return html + "<script>mermaid.initialize(%s);</script>" % json.dumps(init_properties)

0 commit comments

Comments
 (0)