diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.py index 5330f4914f..57586075e5 100644 --- a/zerver/templatetags/app_filters.py +++ b/zerver/templatetags/app_filters.py @@ -118,26 +118,25 @@ def render_markdown_path(markdown_file_path: str, jinja = engines['Jinja2'] - if pure_markdown: - # For files such as /etc/zulip/terms.md where we don't intend - # to use Jinja2 template variables, we still try to load the - # template using Jinja2 (in case the file path isn't absolute - # and does happen to be in Jinja's recognized template - # directories), and if that fails, we try to load it directly - # from disk. - try: - markdown_string = jinja.env.loader.get_source(jinja.env, markdown_file_path)[0] - except TemplateNotFound: - with open(markdown_file_path) as fp: - markdown_string = fp.read() - - rendered_html = md_engine.convert(markdown_string) - else: + try: # By default, we do both Jinja2 templating and markdown # processing on the file, to make it easy to use both Jinja2 # context variables and markdown includes in the file. markdown_string = jinja.env.loader.get_source(jinja.env, markdown_file_path)[0] - html = md_engine.convert(markdown_string) - rendered_html = jinja.from_string(html).render(context) + except TemplateNotFound as e: + if pure_markdown: + # For files such as /etc/zulip/terms.md where we don't intend + # to use Jinja2 template variables, we still try to load the + # template using Jinja2 (in case the file path isn't absolute + # and does happen to be in Jinja's recognized template + # directories), and if that fails, we try to load it directly + # from disk. + with open(markdown_file_path) as fp: + markdown_string = fp.read() + else: + raise e + + html = md_engine.convert(markdown_string) + rendered_html = jinja.from_string(html).render(context) return mark_safe(rendered_html)