Skip to content

Commit 9e2917f

Browse files
authored
Update code base for mkdocstrings 0.30
1 parent f2c8f1a commit 9e2917f

5 files changed

Lines changed: 20 additions & 24 deletions

File tree

mkdocstrings_handlers/crystal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections.abc import Mapping, Sequence
44
from typing import Any
55

6-
from mkdocstrings.handlers.base import BaseHandler
6+
from mkdocstrings import BaseHandler
77

88
from . import inventory
99
from .collector import CrystalCollector

mkdocstrings_handlers/crystal/collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from functools import cached_property
1414
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
1515

16-
from mkdocstrings.handlers.base import BaseHandler, CollectionError
16+
from mkdocstrings import BaseHandler, CollectionError
1717

1818
from . import inventory
1919
from .items import DocConstant, DocItem, DocLocation, DocMapping, DocMethod, DocModule, DocType

mkdocstrings_handlers/crystal/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from functools import cached_property
1010
from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar, overload
1111

12-
from mkdocstrings.handlers.base import CollectionError
12+
from mkdocstrings import CollectionError
1313

1414
from . import crystal_html
1515

mkdocstrings_handlers/crystal/renderer.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,32 @@
22

33
import contextlib
44
import xml.etree.ElementTree as etree
5-
from collections.abc import Mapping
6-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING
76

87
import jinja2
98
import markdown_callouts
109
from markdown.treeprocessors import Treeprocessor
1110
from markupsafe import Markup
12-
from mkdocstrings.handlers import base
11+
from mkdocstrings import BaseHandler, CollectionError, HandlerOptions
1312

1413
from . import crystal_html
1514

1615
if TYPE_CHECKING:
17-
from markdown import Markdown
18-
1916
from .items import DocItem, DocPath
2017

2118

22-
class CrystalRenderer(base.BaseHandler):
19+
class CrystalRenderer(BaseHandler):
2320
fallback_theme = "material"
2421

2522
@property
2623
def collector(self):
2724
return self
2825

29-
def render(self, data: DocItem, config: Mapping[str, Any]) -> str:
26+
def render(self, data: DocItem, options: HandlerOptions, *, locale: str | None = None) -> str:
3027
subconfig = {
3128
"show_source_links": True,
3229
"heading_level": 2,
33-
**config,
30+
**options,
3431
}
3532
template = self.env.get_template(data._TEMPLATE)
3633

@@ -46,21 +43,20 @@ def render(self, data: DocItem, config: Mapping[str, Any]) -> str:
4643
def get_anchors(cls, data: DocItem) -> tuple[str, ...]:
4744
return (data.abs_id,)
4845

49-
def update_env(self, md: Markdown, config: dict) -> None:
50-
super().update_env(md, config)
51-
self._md = md
52-
46+
def update_env(self, config: dict) -> None:
5347
self._pymdownx_hl = None
54-
for ext in md.registeredExtensions:
48+
for ext in self.md.registeredExtensions:
5549
with contextlib.suppress(AttributeError):
5650
self._pymdownx_hl = ext.get_pymdownx_highlighter() # type: ignore[attr-defined]
5751

5852
# Disallow raw HTML.
59-
md.preprocessors.deregister("html_block")
60-
md.inlinePatterns.deregister("html")
53+
self.md.preprocessors.deregister("html_block")
54+
self.md.inlinePatterns.deregister("html")
6155

62-
md.treeprocessors.register(_RefInsertingTreeprocessor(md), "mkdocstrings_crystal_xref", 12)
63-
markdown_callouts.CalloutsExtension().extendMarkdown(md)
56+
self.md.treeprocessors.register(
57+
_RefInsertingTreeprocessor(self.md), "mkdocstrings_crystal_xref", 12
58+
)
59+
markdown_callouts.CalloutsExtension().extendMarkdown(self.md)
6460

6561
self.env.trim_blocks = True
6662
self.env.lstrip_blocks = True
@@ -94,7 +90,7 @@ def do_reference(self, path: str | DocPath, text: str | None = None) -> str:
9490
return text
9591
try:
9692
ref_obj = self.collector.root.lookup(path)
97-
except base.CollectionError:
93+
except CollectionError:
9894
return text
9995
else:
10096
return Markup('<span data-autorefs-optional="{}">{}</span>').format(
@@ -104,7 +100,7 @@ def do_reference(self, path: str | DocPath, text: str | None = None) -> str:
104100
def do_convert_markdown_ctx(
105101
self, text: str, context: DocItem, heading_level: int, html_id: str
106102
):
107-
p: _RefInsertingTreeprocessor = self._md.treeprocessors["mkdocstrings_crystal_xref"] # type: ignore[assignment]
103+
p: _RefInsertingTreeprocessor = self.md.treeprocessors["mkdocstrings_crystal_xref"] # type: ignore[assignment]
108104
p.context = context
109105
return super().do_convert_markdown(text, heading_level=heading_level, html_id=html_id)
110106

@@ -147,7 +143,7 @@ def run(self, root: etree.Element):
147143
assert self.context, "Bug: `CrystalRenderer` should have set the `context` member"
148144
try:
149145
ref_obj = self.context.lookup("".join(el.itertext()))
150-
except base.CollectionError:
146+
except CollectionError:
151147
continue
152148

153149
# Replace the `code` with a new `span` (need to propagate the tail too).

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ classifiers = [
3434
dynamic = ["version"]
3535
requires-python = ">=3.9"
3636
dependencies = [
37-
"mkdocstrings >=0.19.0",
37+
"mkdocstrings >=0.30.0",
3838
"markdown-callouts >=0.1.0",
3939
"mkdocs-autorefs >=0.3.1",
4040
"markupsafe >=1.1.1",

0 commit comments

Comments
 (0)