Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from Feb 22, 2024

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__.

src/mkdocstrings/handlers/rendering.py Outdated Show resolved Hide resolved
src/mkdocstrings/handlers/rendering.py Show resolved Hide resolved
src/mkdocstrings/handlers/rendering.py Show resolved Hide resolved
@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
33 of 35 checks passed
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.

None yet

2 participants