Skip to content

Commit

Permalink
fixup! feat: Add option to scan and register HTML anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin authored and pawamoy committed Feb 23, 2024
1 parent ec47ac2 commit bd1a636
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/mkdocs_autorefs/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ def _scan_anchors(self, parent: Element, pending_anchors: _PendingAnchors) -> No
# We found an anchor. Record its id if it has one.
if anchor_id := el.get("id"):
pending_anchors.append(anchor_id)
# If the element has text or a link, it's not an alias.
# Non-whitespace text after the element interrupts the chain, aliases can't apply.
if el.tail and el.tail.strip():
if el.text or el.get("href") or (el.tail and el.tail.strip()):
pending_anchors.flush()

elif el.tag == "p":
Expand Down
10 changes: 9 additions & 1 deletion tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,14 @@ def test_register_markdown_anchors() -> None:
[](){#alias5}
[](){#alias6}
Decoy.
## Heading more
## Heading more1
[](){#alias7}
[decoy](){#alias8}
[](){#alias9}
## Heading more2
[](){#alias10}
""",
),
)
Expand All @@ -273,4 +278,7 @@ def test_register_markdown_anchors() -> None:
"alias5": "page#alias5",
"alias6": "page#alias6",
"alias7": "page#alias7",
"alias8": "page#alias8",
"alias9": "page#heading-more2",
"alias10": "page#alias10",
}

0 comments on commit bd1a636

Please sign in to comment.