Skip to content

Commit 5bad7fa

Browse files
committed
fixup! wip
1 parent eeedcdf commit 5bad7fa

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/mkdocs_autorefs/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class AutorefsPlugin(BasePlugin[AutorefsConfig]):
107107
"""
108108

109109
scan_toc: bool = True
110+
record_backlinks: bool = False
110111
current_page: Page | None = None
111112
# YORE: Bump 2: Remove line.
112113
legacy_refs: bool = True
@@ -453,7 +454,9 @@ def on_env(self, env: Environment, /, *, config: MkDocsConfig, files: Files) ->
453454
from_url=file.page.url,
454455
fallback=self.get_fallback_anchor,
455456
)
456-
backlink_recorder = functools.partial(self._record_backlink, page_url=file.page.url)
457+
backlink_recorder = (
458+
functools.partial(self._record_backlink, page_url=file.page.url) if self.record_backlinks else None
459+
)
457460
# YORE: Bump 2: Replace `, _legacy_refs=self.legacy_refs` with `` within line.
458461
file.page.content, unmapped = fix_refs(
459462
file.page.content,

src/mkdocs_autorefs/references.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from markupsafe import Markup
2424

2525
if TYPE_CHECKING:
26-
from collections.abc import Iterable, Iterator
26+
from collections.abc import Iterable
2727
from pathlib import Path
2828
from re import Match
2929

@@ -378,13 +378,6 @@ def _find_url(identifiers: Iterable[str], url_mapper: Callable[[str], URLAndTitl
378378
raise KeyError(f"None of the identifiers {identifiers} were found")
379379

380380

381-
def _find_backlinks(html: str) -> Iterator[tuple[str, str, str]]:
382-
for match in AUTOREF_RE.finditer(html):
383-
attrs = _html_attrs_parser.parse(f"<a {match['attrs']}>")
384-
if (backlink_type := attrs.get("backlink-type")) and (backlink_anchor := attrs.get("backlink-anchor")):
385-
yield attrs["identifier"], backlink_type, backlink_anchor
386-
387-
388381
def _tooltip(identifier: str, title: str | None) -> str:
389382
if title:
390383
if title == identifier:

tests/test_references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010

1111
from mkdocs_autorefs.plugin import AutorefsPlugin
12-
from mkdocs_autorefs.references import AutorefsExtension, AutorefsHookInterface, fix_refs, relative_url
12+
from mkdocs_autorefs.references import AutorefsExtension, AutorefsHookInterface, URLAndTitle, fix_refs, relative_url
1313
from tests.helpers import create_page
1414

1515
if TYPE_CHECKING:
@@ -66,7 +66,7 @@ def run_references_test(
6666
md = markdown.Markdown(extensions=[AutorefsExtension(), *extensions], extension_configs=extensions)
6767
content = md.convert(source)
6868

69-
def url_mapper(identifier: str) -> tuple[str, str | None]:
69+
def url_mapper(identifier: str) -> URLAndTitle:
7070
return relative_url(from_url, url_map[identifier]), None
7171

7272
actual_output, actual_unmapped = fix_refs(content, url_mapper)

0 commit comments

Comments
 (0)