diff --git a/src/mkdocs_autorefs/references.py b/src/mkdocs_autorefs/references.py index 489b21b..bc72c81 100644 --- a/src/mkdocs_autorefs/references.py +++ b/src/mkdocs_autorefs/references.py @@ -9,7 +9,6 @@ from dataclasses import dataclass from html import escape, unescape from html.parser import HTMLParser -from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, ClassVar, Match from urllib.parse import urlsplit from xml.etree.ElementTree import Element @@ -22,6 +21,8 @@ from markdown.util import HTML_PLACEHOLDER_RE, INLINE_PLACEHOLDER_RE if TYPE_CHECKING: + from pathlib import Path + from markdown import Markdown from mkdocs_autorefs.plugin import AutorefsPlugin @@ -58,11 +59,13 @@ def __getattr__(name: str) -> Any: """ -class AutoRefHookInterface(ABC): +class AutorefsHookInterface(ABC): """An interface for hooking into how AutoRef handles inline references.""" @dataclass class Context: + """The context around an auto-reference.""" + domain: str role: str origin: str @@ -70,12 +73,13 @@ class Context: lineno: int def as_dict(self) -> dict[str, str]: + """Convert the context to a dictionary of HTML attributes.""" return { - "data-autorefs-domain": self.domain, - "data-autorefs-role": self.role, - "data-autorefs-origin": self.origin, - "data-autorefs-filepath": str(self.filepath), - "data-autorefs-lineno": str(self.lineno), + "domain": self.domain, + "role": self.role, + "origin": self.origin, + "filepath": str(self.filepath), + "lineno": str(self.lineno), } @abstractmethod @@ -91,7 +95,7 @@ def expand_identifier(self, identifier: str) -> str: raise NotImplementedError @abstractmethod - def get_context(self) -> AutoRefHookInterface.Context: + def get_context(self) -> AutorefsHookInterface.Context: """Get the current context. Returns: @@ -104,7 +108,7 @@ class AutorefsInlineProcessor(ReferenceInlineProcessor): """A Markdown extension to handle inline references.""" name: str = "mkdocs-autorefs" - hook: AutoRefHookInterface | None = None + hook: AutorefsHookInterface | None = None def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D107 super().__init__(REFERENCE_RE, *args, **kwargs)