Skip to content

Commit ffcaa01

Browse files
committed
refactor: Rename AutoRefInlineProcessor to AutorefsInlineProcessor
1 parent ae87ff7 commit ffcaa01

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/mkdocs_autorefs/references.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import re
7+
import warnings
78
from html import escape, unescape
89
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Match
910
from urllib.parse import urlsplit
@@ -29,6 +30,14 @@
2930
# TODO: remove once support for MkDocs <1.5 is dropped
3031
log = logging.getLogger(f"mkdocs.plugins.{__name__}") # type: ignore[assignment]
3132

33+
34+
def __getattr__(name: str) -> Any:
35+
if name == "AutoRefInlineProcessor":
36+
warnings.warn("AutoRefInlineProcessor was renamed AutorefsInlineProcessor", DeprecationWarning, stacklevel=2)
37+
return AutorefsInlineProcessor
38+
raise AttributeError(f"module 'mkdocs_autorefs.references' has no attribute {name}")
39+
40+
3241
_ATTR_VALUE = r'"[^"<>]+"|[^"<> ]+' # Possibly with double quotes around
3342
AUTO_REF_RE = re.compile(
3443
rf"<span data-(?P<kind>autorefs-(?:identifier|optional|optional-hover))=(?P<identifier>{_ATTR_VALUE})"
@@ -40,8 +49,8 @@
4049
"""
4150

4251

43-
class AutoRefInlineProcessor(ReferenceInlineProcessor):
44-
"""A Markdown extension."""
52+
class AutorefsInlineProcessor(ReferenceInlineProcessor):
53+
"""A Markdown extension to handle inline references."""
4554

4655
name: str = "mkdocs-autorefs"
4756

@@ -292,7 +301,13 @@ def flush(self, alias_to: str | None = None) -> None:
292301

293302

294303
class AutorefsExtension(Extension):
295-
"""Extension that inserts auto-references in Markdown."""
304+
"""Markdown extension that transforms unresolved references into auto-references.
305+
306+
Auto-references are then resolved later by the MkDocs plugin.
307+
308+
This extension also scans Markdown anchors (`[](){#some-id}`)
309+
to register them with the MkDocs plugin.
310+
"""
296311

297312
def __init__(
298313
self,
@@ -311,16 +326,16 @@ def __init__(
311326
def extendMarkdown(self, md: Markdown) -> None: # noqa: N802 (casing: parent method's name)
312327
"""Register the extension.
313328
314-
Add an instance of our [`AutoRefInlineProcessor`][mkdocs_autorefs.references.AutoRefInlineProcessor] to the Markdown parser.
329+
Add an instance of our [`AutorefsInlineProcessor`][mkdocs_autorefs.references.AutorefsInlineProcessor] to the Markdown parser.
315330
Also optionally add an instance of our [`AnchorScannerTreeProcessor`][mkdocs_autorefs.references.AnchorScannerTreeProcessor]
316331
to the Markdown parser if a reference to the autorefs plugin was passed to this extension.
317332
318333
Arguments:
319334
md: A `markdown.Markdown` instance.
320335
"""
321336
md.inlinePatterns.register(
322-
AutoRefInlineProcessor(md),
323-
AutoRefInlineProcessor.name,
337+
AutorefsInlineProcessor(md),
338+
AutorefsInlineProcessor.name,
324339
priority=168, # Right after markdown.inlinepatterns.ReferenceInlineProcessor
325340
)
326341
if self.plugin is not None and self.plugin.scan_toc and "attr_list" in md.treeprocessors:

0 commit comments

Comments
 (0)