integrations-docs: Move markdown macros include files.

Moves files in `templates/zerver/help/include` that are used
specifically for integrations documentation to be in a new
directory: `templates/zerver/integrations/include`.

Adds a boolean parameter to `render_markdown_path` to be used
for integrations documentation pages.
This commit is contained in:
Lauryn Menard 2022-12-07 19:43:49 +01:00 committed by Tim Abbott
parent 53f705c7bd
commit 5f9dc76d54
19 changed files with 14 additions and 7 deletions

View File

@ -64,7 +64,7 @@ phrases and steps at the location of the macros. Macros help eliminate
repeated content in our documentation.
The source for macros is the Markdown files under
`templates/zerver/help/include` in the
`templates/zerver/integrations/include/` in the
[main Zulip server repository](https://github.com/zulip/zulip). If you find
multiple instances of particular content in the documentation, you can
always create a new macro by adding a new file to that folder.

View File

@ -83,7 +83,10 @@ docs_without_macros = [
@items_tuple_to_dict
@register.filter(name="render_markdown_path", is_safe=True)
def render_markdown_path(
markdown_file_path: str, context: Optional[Dict[str, Any]] = None, pure_markdown: bool = False
markdown_file_path: str,
context: Optional[Dict[str, Any]] = None,
pure_markdown: bool = False,
integration_doc: bool = False,
) -> str:
"""Given a path to a Markdown file, return the rendered HTML.
@ -127,10 +130,6 @@ def render_markdown_path(
zerver.lib.markdown.help_relative_links.makeExtension(),
zerver.lib.markdown.help_emoticon_translations_table.makeExtension(),
]
if md_macro_extension is None:
md_macro_extension = zerver.lib.markdown.include.makeExtension(
base_path="templates/zerver/help/include/"
)
if "api_url" in context:
# We need to generate the API code examples extension each
# time so the `api_url` config parameter can be set dynamically.
@ -146,6 +145,14 @@ def render_markdown_path(
else:
extensions = md_extensions
if integration_doc:
md_macro_extension = zerver.lib.markdown.include.makeExtension(
base_path="templates/zerver/integrations/include/"
)
else:
md_macro_extension = zerver.lib.markdown.include.makeExtension(
base_path="templates/zerver/help/include/"
)
if not any(doc in markdown_file_path for doc in docs_without_macros):
extensions = [md_macro_extension, *extensions]

View File

@ -325,6 +325,6 @@ def integration_doc(request: HttpRequest, integration_name: str = REQ()) -> Http
if isinstance(integration, HubotIntegration):
context["hubot_docs_url"] = integration.hubot_docs_url
doc_html_str = render_markdown_path(integration.doc, context)
doc_html_str = render_markdown_path(integration.doc, context, integration_doc=True)
return HttpResponse(doc_html_str)