diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.py index 85ab460251..35f17d8493 100644 --- a/zerver/templatetags/app_filters.py +++ b/zerver/templatetags/app_filters.py @@ -1,7 +1,7 @@ from typing import Dict, Optional, Any from django.conf import settings -from django.template import Library, loader +from django.template import Library, loader, engines from django.utils.safestring import mark_safe from django.utils.lru_cache import lru_cache @@ -82,7 +82,8 @@ def render_markdown_path(markdown_file_path, context=None): if context is None: context = {} - template = loader.get_template(markdown_file_path) - markdown_string = template.render(context) + jinja = engines['Jinja2'] + markdown_string = jinja.env.loader.get_source(jinja.env, markdown_file_path)[0] html = md_engine.convert(markdown_string) - return mark_safe(html) + html_template = jinja.from_string(html) + return mark_safe(html_template.render(context)) diff --git a/zproject/jinja2/backends.py b/zproject/jinja2/backends.py index a094452b05..ae5683283f 100644 --- a/zproject/jinja2/backends.py +++ b/zproject/jinja2/backends.py @@ -46,6 +46,12 @@ class Jinja2(django_jinja2.Jinja2): six.reraise(TemplateSyntaxError, TemplateSyntaxError(exc.args), sys.exc_info()[2]) + def from_string(self, template_code): + # type: (str) -> Template + return Template(self.env.from_string(template_code), + self.context_processors, + self.debug) + class Template(django_jinja2.Template): """Context processors aware Template. diff --git a/zproject/settings.py b/zproject/settings.py index d25debf1ed..d4e7023239 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -298,6 +298,7 @@ if PRODUCTION: TEMPLATES = [ { + 'NAME': 'Jinja2', 'BACKEND': 'zproject.jinja2.backends.Jinja2', 'DIRS': [ os.path.join(DEPLOY_ROOT, 'templates'),