zulip/zerver/lib/markdown
Alex Vandiver fa6daee4e1 markdown: Fix use of pure_markdown for non-pure markdown rendering.
`render_markdown_path` renders Markdown, and also (since baff121115)
runs Jinja2 on the resulting HTML.

The `pure_markdown` flag was added in 0a99fa2fd6, and did two
things: retried the path directly in the filesystem if it wasn't found
by the Jinja2 resolver, and also skipped the subsequent Jinja2
templating step (regardless of where the content was found).  In this
context, the name `pure_markdown` made some sense.  The only two
callsites were the TOS and privacy policy renders, which might have
had user-supplied arbitrary paths, and we wished to handle absolute
paths in addition to ones inside `templates/`.

Unfortunately, the follow-up of 01bd55bbcb did not refactor the
logic -- it changed it, by making `pure_markdown` only do the former
of the two behaviors.  Passing `pure_markdown=True` after that commit
still caused it to always run Jinja2, but allowed it to look elsewhere
in the filesystem.

This set the stage for calls, such as the one introduced in
dedea23745, which passed both a context for Jinja2, as well as
`pure_markdown=True` implying that Jinja2 was not to be used.

Split the two previous behaviors of the `pure_markdown` flag, and use
pre-existing data to control them, rather than an explicit flag.  For
handling policy information which is stored at an absolute path
outside of the template root, we switch to using the template search
path if and only if the path is relative.  This also closes the
potential inconsistency based on CWD when `pure_markdown=True` was
passed and the path was relative, not absolute.

Decide whether to run Jinja2 based on if a context is passed in at
all.  This restores the behavior in the initial 0a99fa2fd6 where a
call to `rendar_markdown_path` could be made to just render markdown,
and not some other unmentioned and unrelated templating language as
well.
2023-03-17 08:46:25 -07:00
..
__init__.py requirements: Upgrade Python requirements. 2023-03-05 14:46:28 -08:00
api_arguments_table_generator.py black: Reformat with Black 23. 2023-02-02 10:40:13 -08:00
api_return_values_table_generator.py response: Implement ignored parameters with MutableJsonResponse class. 2023-03-06 10:33:13 -08:00
fenced_code.py markdown: Fix use of pure_markdown for non-pure markdown rendering. 2023-03-17 08:46:25 -07:00
help_emoticon_translations_table.py markdown: Rename preprocessor_priorities module to priorities. 2022-06-26 17:36:31 -07:00
help_relative_links.py help center: Update relative gear menu macro for organization settings. 2023-01-26 10:17:45 -08:00
help_settings_links.py help: Improve relative settings links for documentation on bots. 2023-02-06 15:06:15 -08:00
include.py ruff: Fix N818 exception name should be named with an Error suffix. 2022-11-17 16:52:00 -08:00
nested_code_blocks.py ruff: Fix SIM102 nested `if` statements. 2023-01-23 11:18:36 -08:00
priorities.py markdown: Rewrite /static/ images to use staticfiles_storage.url. 2023-02-14 17:17:06 -05:00
static.py markdown: Rewrite /static/ images to use staticfiles_storage.url. 2023-02-14 17:17:06 -05:00
tabbed_sections.py help: Add a dedicated page on how to add emphasis to text. 2023-03-16 10:51:57 -07:00
testing_mocks.py python: Reformat with Black, except quotes. 2021-02-12 13:11:19 -08:00