Skip to content

Commit

Permalink
fix: handle multiple handler's envs on same doc.
Browse files Browse the repository at this point in the history
Instead of a boolean of has any env been updated, track by handle name
which env has been updated.

References: mkdocstrings#201
Fixes: 502
  • Loading branch information
jdpatt committed Jan 6, 2023
1 parent d965ccc commit 1b84b44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
self._config = config
self._handlers = handlers
self._autorefs = autorefs
self._updated_env = False
self._updated_envs: list = []

def test(self, parent: Element, block: str) -> bool:
"""Match our autodoc instructions.
Expand Down Expand Up @@ -197,10 +197,10 @@ def _process_block(
log.error(f"Error reading page '{self._autorefs.current_page}':")
raise PluginError(f"Could not collect '{identifier}'") from exception

if not self._updated_env:
if handler_name not in self._updated_envs: # We haven't seen this handler before on this document.
log.debug("Updating renderer's env")
handler._update_env(self.md, self._config) # noqa: WPS437 (protected member OK)
self._updated_env = True
self._updated_envs.append(handler_name)

log.debug("Rendering templates")
try:
Expand Down
1 change: 1 addition & 0 deletions src/mkdocstrings/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: W0613 (unused
self.env.filters["heading"] = self.do_heading

def _update_env(self, md: Markdown, config: dict):
"""Update our handler to point to our configured Markdown instance, grabbing some of the config from `md`."""
extensions = config["mdx"] + [MkdocstringsInnerExtension(self._headings)]

new_md = Markdown(extensions=extensions, extension_configs=config["mdx_configs"])
Expand Down

0 comments on commit 1b84b44

Please sign in to comment.