4
4
5
5
import logging
6
6
import re
7
+ import warnings
7
8
from html import escape , unescape
8
9
from typing import TYPE_CHECKING , Any , Callable , ClassVar , Match
9
10
from urllib .parse import urlsplit
29
30
# TODO: remove once support for MkDocs <1.5 is dropped
30
31
log = logging .getLogger (f"mkdocs.plugins.{ __name__ } " ) # type: ignore[assignment]
31
32
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
+
32
41
_ATTR_VALUE = r'"[^"<>]+"|[^"<> ]+' # Possibly with double quotes around
33
42
AUTO_REF_RE = re .compile (
34
43
rf"<span data-(?P<kind>autorefs-(?:identifier|optional|optional-hover))=(?P<identifier>{ _ATTR_VALUE } )"
40
49
"""
41
50
42
51
43
- class AutoRefInlineProcessor (ReferenceInlineProcessor ):
44
- """A Markdown extension."""
52
+ class AutorefsInlineProcessor (ReferenceInlineProcessor ):
53
+ """A Markdown extension to handle inline references ."""
45
54
46
55
name : str = "mkdocs-autorefs"
47
56
@@ -292,7 +301,13 @@ def flush(self, alias_to: str | None = None) -> None:
292
301
293
302
294
303
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
+ """
296
311
297
312
def __init__ (
298
313
self ,
@@ -311,16 +326,16 @@ def __init__(
311
326
def extendMarkdown (self , md : Markdown ) -> None : # noqa: N802 (casing: parent method's name)
312
327
"""Register the extension.
313
328
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.
315
330
Also optionally add an instance of our [`AnchorScannerTreeProcessor`][mkdocs_autorefs.references.AnchorScannerTreeProcessor]
316
331
to the Markdown parser if a reference to the autorefs plugin was passed to this extension.
317
332
318
333
Arguments:
319
334
md: A `markdown.Markdown` instance.
320
335
"""
321
336
md .inlinePatterns .register (
322
- AutoRefInlineProcessor (md ),
323
- AutoRefInlineProcessor .name ,
337
+ AutorefsInlineProcessor (md ),
338
+ AutorefsInlineProcessor .name ,
324
339
priority = 168 , # Right after markdown.inlinepatterns.ReferenceInlineProcessor
325
340
)
326
341
if self .plugin is not None and self .plugin .scan_toc and "attr_list" in md .treeprocessors :
0 commit comments