mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Reuse Jinja2 tojson builtin filter (#2713)
Also drop Markupsafe from requirements
This commit is contained in:
@@ -112,7 +112,6 @@ class Theme:
|
||||
loader = jinja2.FileSystemLoader(self.dirs)
|
||||
# No autoreload because editing a template in the middle of a build is not useful.
|
||||
env = jinja2.Environment(loader=loader, auto_reload=False)
|
||||
env.filters['tojson'] = filters.tojson
|
||||
env.filters['url'] = filters.url_filter
|
||||
localization.install_translations(env, self._vars['locale'], self.dirs)
|
||||
return env
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
{% if page %}
|
||||
<script>
|
||||
// Current page data
|
||||
var mkdocs_page_name = {{ page.title|tojson|safe }};
|
||||
var mkdocs_page_input_path = {{ page.file.src_path|string|tojson|safe }};
|
||||
var mkdocs_page_url = {{ page.abs_url|tojson|safe }};
|
||||
var mkdocs_page_name = {{ page.title|tojson }};
|
||||
var mkdocs_page_input_path = {{ page.file.src_path|string|tojson }};
|
||||
var mkdocs_page_url = {{ page.abs_url|tojson }};
|
||||
</script>
|
||||
{% endif %}
|
||||
<script src="{{ 'js/jquery-3.6.0.min.js'|url }}" defer></script>
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import json
|
||||
|
||||
import jinja2
|
||||
import markupsafe
|
||||
|
||||
from mkdocs.utils import normalize_url
|
||||
|
||||
|
||||
def tojson(obj, **kwargs):
|
||||
return markupsafe.Markup(json.dumps(obj, **kwargs))
|
||||
|
||||
|
||||
@jinja2.contextfilter
|
||||
def url_filter(context, value):
|
||||
""" A Template filter to normalize URLs. """
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
babel==2.9.0
|
||||
click==3.3
|
||||
Jinja2==2.10.1
|
||||
MarkupSafe==0.23
|
||||
Markdown==3.2.1
|
||||
PyYAML==5.1
|
||||
watchdog==2.0.0
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
babel>=2.9.0
|
||||
click>=7.0
|
||||
Jinja2>=2.10.3
|
||||
MarkupSafe>=0.23
|
||||
Markdown>=3.2.1
|
||||
PyYAML>=5.2
|
||||
watchdog>=2.0.0
|
||||
|
||||
Reference in New Issue
Block a user