Reuse Jinja2 tojson builtin filter (#2713)

Also drop Markupsafe from requirements
This commit is contained in:
Álvaro Mondéjar
2021-12-30 22:06:33 +01:00
committed by GitHub
parent 9fb40be97f
commit cc88b5a680
5 changed files with 3 additions and 13 deletions

View File

@@ -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

View File

@@ -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>

View File

@@ -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. """

View File

@@ -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

View File

@@ -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