mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	markdown: Fix use of pure_markdown for non-pure markdown rendering.
`render_markdown_path` renders Markdown, and also (sincebaff121115) runs Jinja2 on the resulting HTML. The `pure_markdown` flag was added in0a99fa2fd6, 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 of01bd55bbcbdid 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 indedea23745, 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 initial0a99fa2fd6where a call to `rendar_markdown_path` could be made to just render markdown, and not some other unmentioned and unrelated templating language as well.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							24f24d236d
						
					
				
				
					commit
					fa6daee4e1
				
			@@ -16,11 +16,11 @@
 | 
			
		||||
            {% endif %}
 | 
			
		||||
 | 
			
		||||
            {% if page_is_policy_center %}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index) }}
 | 
			
		||||
            {% elif page_is_help_center %}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index) }}
 | 
			
		||||
            {% else %}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index, context=api_uri_context, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(sidebar_index, context=api_uri_context) }}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
 | 
			
		||||
            {% if not page_is_policy_center %}
 | 
			
		||||
@@ -36,11 +36,11 @@
 | 
			
		||||
    <div class="markdown">
 | 
			
		||||
        <div class="content">
 | 
			
		||||
            {% if page_is_policy_center %}
 | 
			
		||||
            {{ render_markdown_path(article, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(article) }}
 | 
			
		||||
            {% elif page_is_help_center %}
 | 
			
		||||
            {{ render_markdown_path(article, context=api_uri_context, help_center=True, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(article, context=api_uri_context, help_center=True) }}
 | 
			
		||||
            {% else %}
 | 
			
		||||
            {{ render_markdown_path(article, context=api_uri_context, pure_markdown=True) }}
 | 
			
		||||
            {{ render_markdown_path(article, context=api_uri_context) }}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
 | 
			
		||||
            <div class="documentation-footer">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user