Skip to content

Comments

refactor: Backup anchors without hrefs, for compatibility with autorefs' Markdown anchors#651

Merged
pawamoy merged 9 commits intomainfrom
duplicate-anchors
Feb 22, 2024
Merged

refactor: Backup anchors without hrefs, for compatibility with autorefs' Markdown anchors#651
pawamoy merged 9 commits intomainfrom
duplicate-anchors

Conversation

@pawamoy
Copy link
Member

@pawamoy pawamoy commented Feb 20, 2024

This will be useful for the soon-to-come Markdown anchors feature of mkdocs-autorefs.

Related to mkdocs-autorefs#39: mkdocstrings/autorefs#39

@pawamoy pawamoy requested a review from oprypin February 20, 2024 18:00
@pawamoy pawamoy marked this pull request as ready for review February 20, 2024 18:00
@pawamoy
Copy link
Member Author

pawamoy commented Feb 20, 2024

I first went with a custom iterator approach (yielding parent, index, element) to insert at the right position, but since it iterated forward and we had to insert at position or position + 1 it was causing infinite loops.

Instead, I used a recursive approach, and at each layer I iterate on elements backwards to be able to insert in the being-iterated elements. The other option was to iterate on a copy of the list of elements, but this would have been less efficient. reversed is possible here because Element implements both __len__ and __getitem__.

@oprypin
Copy link
Member

oprypin commented Feb 21, 2024

Looks awesome otherwise :)

@pawamoy pawamoy changed the title refactor: Duplicate anchors instead of modifying them in-place refactor: Backup anchors without hrefs, for compatibility with autorefs' Markdown anchors Feb 22, 2024
@pawamoy
Copy link
Member Author

pawamoy commented Feb 22, 2024

OK LGTM! Squashing incoming 🙂

@pawamoy pawamoy merged commit b5236b4 into main Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants