diff --git a/src/mkdocs_autorefs/references.py b/src/mkdocs_autorefs/references.py index 2fe1d6a..fc39810 100644 --- a/src/mkdocs_autorefs/references.py +++ b/src/mkdocs_autorefs/references.py @@ -4,6 +4,7 @@ import logging import re +import warnings from html import escape, unescape from typing import TYPE_CHECKING, Any, Callable, ClassVar, Match from urllib.parse import urlsplit @@ -29,6 +30,14 @@ # TODO: remove once support for MkDocs <1.5 is dropped log = logging.getLogger(f"mkdocs.plugins.{__name__}") # type: ignore[assignment] + +def __getattr__(name: str) -> Any: + if name == "AutoRefInlineProcessor": + warnings.warn("AutoRefInlineProcessor was renamed AutorefsInlineProcessor", DeprecationWarning, stacklevel=2) + return AutorefsInlineProcessor + raise AttributeError(f"module 'mkdocs_autorefs.references' has no attribute {name}") + + _ATTR_VALUE = r'"[^"<>]+"|[^"<> ]+' # Possibly with double quotes around AUTO_REF_RE = re.compile( rf"autorefs-(?:identifier|optional|optional-hover))=(?P{_ATTR_VALUE})" @@ -40,8 +49,8 @@ """ -class AutoRefInlineProcessor(ReferenceInlineProcessor): - """A Markdown extension.""" +class AutorefsInlineProcessor(ReferenceInlineProcessor): + """A Markdown extension to handle inline references.""" name: str = "mkdocs-autorefs" @@ -292,7 +301,13 @@ def flush(self, alias_to: str | None = None) -> None: class AutorefsExtension(Extension): - """Extension that inserts auto-references in Markdown.""" + """Markdown extension that transforms unresolved references into auto-references. + + Auto-references are then resolved later by the MkDocs plugin. + + This extension also scans Markdown anchors (`[](){#some-id}`) + to register them with the MkDocs plugin. + """ def __init__( self, @@ -311,7 +326,7 @@ def __init__( def extendMarkdown(self, md: Markdown) -> None: # noqa: N802 (casing: parent method's name) """Register the extension. - Add an instance of our [`AutoRefInlineProcessor`][mkdocs_autorefs.references.AutoRefInlineProcessor] to the Markdown parser. + Add an instance of our [`AutorefsInlineProcessor`][mkdocs_autorefs.references.AutorefsInlineProcessor] to the Markdown parser. Also optionally add an instance of our [`AnchorScannerTreeProcessor`][mkdocs_autorefs.references.AnchorScannerTreeProcessor] to the Markdown parser if a reference to the autorefs plugin was passed to this extension. @@ -319,8 +334,8 @@ def extendMarkdown(self, md: Markdown) -> None: # noqa: N802 (casing: parent me md: A `markdown.Markdown` instance. """ md.inlinePatterns.register( - AutoRefInlineProcessor(md), - AutoRefInlineProcessor.name, + AutorefsInlineProcessor(md), + AutorefsInlineProcessor.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: