diff --git a/mkdocstrings_handlers/crystal/__init__.py b/mkdocstrings_handlers/crystal/__init__.py index 7bd4a48..ee8fa4a 100644 --- a/mkdocstrings_handlers/crystal/__init__.py +++ b/mkdocstrings_handlers/crystal/__init__.py @@ -3,7 +3,7 @@ from collections.abc import Mapping, Sequence from typing import Any -from mkdocstrings.handlers.base import BaseHandler +from mkdocstrings import BaseHandler from . import inventory from .collector import CrystalCollector diff --git a/mkdocstrings_handlers/crystal/collector.py b/mkdocstrings_handlers/crystal/collector.py index 04d817d..f7578c5 100644 --- a/mkdocstrings_handlers/crystal/collector.py +++ b/mkdocstrings_handlers/crystal/collector.py @@ -13,7 +13,7 @@ from functools import cached_property from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast -from mkdocstrings.handlers.base import BaseHandler, CollectionError +from mkdocstrings import BaseHandler, CollectionError from . import inventory from .items import DocConstant, DocItem, DocLocation, DocMapping, DocMethod, DocModule, DocType diff --git a/mkdocstrings_handlers/crystal/items.py b/mkdocstrings_handlers/crystal/items.py index 692977d..06a38ec 100644 --- a/mkdocstrings_handlers/crystal/items.py +++ b/mkdocstrings_handlers/crystal/items.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar, overload -from mkdocstrings.handlers.base import CollectionError +from mkdocstrings import CollectionError from . import crystal_html diff --git a/mkdocstrings_handlers/crystal/renderer.py b/mkdocstrings_handlers/crystal/renderer.py index 5018a86..850c581 100644 --- a/mkdocstrings_handlers/crystal/renderer.py +++ b/mkdocstrings_handlers/crystal/renderer.py @@ -2,35 +2,32 @@ import contextlib import xml.etree.ElementTree as etree -from collections.abc import Mapping -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING import jinja2 import markdown_callouts from markdown.treeprocessors import Treeprocessor from markupsafe import Markup -from mkdocstrings.handlers import base +from mkdocstrings import BaseHandler, CollectionError, HandlerOptions from . import crystal_html if TYPE_CHECKING: - from markdown import Markdown - from .items import DocItem, DocPath -class CrystalRenderer(base.BaseHandler): +class CrystalRenderer(BaseHandler): fallback_theme = "material" @property def collector(self): return self - def render(self, data: DocItem, config: Mapping[str, Any]) -> str: + def render(self, data: DocItem, options: HandlerOptions, *, locale: str | None = None) -> str: subconfig = { "show_source_links": True, "heading_level": 2, - **config, + **options, } template = self.env.get_template(data._TEMPLATE) @@ -46,21 +43,20 @@ def render(self, data: DocItem, config: Mapping[str, Any]) -> str: def get_anchors(cls, data: DocItem) -> tuple[str, ...]: return (data.abs_id,) - def update_env(self, md: Markdown, config: dict) -> None: - super().update_env(md, config) - self._md = md - + def update_env(self, config: dict) -> None: self._pymdownx_hl = None - for ext in md.registeredExtensions: + for ext in self.md.registeredExtensions: with contextlib.suppress(AttributeError): self._pymdownx_hl = ext.get_pymdownx_highlighter() # type: ignore[attr-defined] # Disallow raw HTML. - md.preprocessors.deregister("html_block") - md.inlinePatterns.deregister("html") + self.md.preprocessors.deregister("html_block") + self.md.inlinePatterns.deregister("html") - md.treeprocessors.register(_RefInsertingTreeprocessor(md), "mkdocstrings_crystal_xref", 12) - markdown_callouts.CalloutsExtension().extendMarkdown(md) + self.md.treeprocessors.register( + _RefInsertingTreeprocessor(self.md), "mkdocstrings_crystal_xref", 12 + ) + markdown_callouts.CalloutsExtension().extendMarkdown(self.md) self.env.trim_blocks = True self.env.lstrip_blocks = True @@ -94,7 +90,7 @@ def do_reference(self, path: str | DocPath, text: str | None = None) -> str: return text try: ref_obj = self.collector.root.lookup(path) - except base.CollectionError: + except CollectionError: return text else: return Markup('{}').format( @@ -104,7 +100,7 @@ def do_reference(self, path: str | DocPath, text: str | None = None) -> str: def do_convert_markdown_ctx( self, text: str, context: DocItem, heading_level: int, html_id: str ): - p: _RefInsertingTreeprocessor = self._md.treeprocessors["mkdocstrings_crystal_xref"] # type: ignore[assignment] + p: _RefInsertingTreeprocessor = self.md.treeprocessors["mkdocstrings_crystal_xref"] # type: ignore[assignment] p.context = context return super().do_convert_markdown(text, heading_level=heading_level, html_id=html_id) @@ -147,7 +143,7 @@ def run(self, root: etree.Element): assert self.context, "Bug: `CrystalRenderer` should have set the `context` member" try: ref_obj = self.context.lookup("".join(el.itertext())) - except base.CollectionError: + except CollectionError: continue # Replace the `code` with a new `span` (need to propagate the tail too). diff --git a/pyproject.toml b/pyproject.toml index 09a7144..dea3591 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ classifiers = [ dynamic = ["version"] requires-python = ">=3.9" dependencies = [ - "mkdocstrings >=0.19.0", + "mkdocstrings >=0.30.0", "markdown-callouts >=0.1.0", "mkdocs-autorefs >=0.3.1", "markupsafe >=1.1.1",