Skip to content

Commit

Permalink
refactor: Attach name to processors for easier retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy authored May 14, 2024
1 parent 08c8945 commit 036b825
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mkdocs_autorefs/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
class AutoRefInlineProcessor(ReferenceInlineProcessor):
"""A Markdown extension."""

name: str = "mkdocs-autorefs"

def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D107
super().__init__(REFERENCE_RE, *args, **kwargs)

Expand Down Expand Up @@ -224,6 +226,7 @@ def fix_refs(html: str, url_mapper: Callable[[str], str]) -> tuple[str, list[str
class AnchorScannerTreeProcessor(Treeprocessor):
"""Tree processor to scan and register HTML anchors."""

name: str = "mkdocs-autorefs-anchors-scanner"
_htags: ClassVar[set[str]] = {"h1", "h2", "h3", "h4", "h5", "h6"}

def __init__(self, plugin: AutorefsPlugin, md: Markdown | None = None) -> None:
Expand Down Expand Up @@ -317,13 +320,13 @@ def extendMarkdown(self, md: Markdown) -> None: # noqa: N802 (casing: parent me
"""
md.inlinePatterns.register(
AutoRefInlineProcessor(md),
"mkdocs-autorefs",
AutoRefInlineProcessor.name,
priority=168, # Right after markdown.inlinepatterns.ReferenceInlineProcessor
)
if self.plugin is not None and self.plugin.scan_toc and "attr_list" in md.treeprocessors:
log.debug("Enabling Markdown anchors feature")
md.treeprocessors.register(
AnchorScannerTreeProcessor(self.plugin, md),
"mkdocs-autorefs-anchors-scanner",
AnchorScannerTreeProcessor.name,
priority=0,
)

0 comments on commit 036b825

Please sign in to comment.