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

Prevent duplicate id in heading and inserted a tag #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brettbatie
Copy link

If the heading tag already has the exact same id as what will be inserted into the tag, do not add the id to the tag. This helps with plugins like SimpleTOC which adds an id to all of the heading tags.

If the heading tag already has the exact same id as what will be inserted into the <a> tag, do not add the id to the <a> tag. This helps with plugins like SimpleTOC which adds an id to all of the heading tags.
@vyskoczilova
Copy link
Owner

vyskoczilova commented Aug 10, 2022

Hi! Thanks for the PR! How I should test it?

@brettbatie
Copy link
Author

You can manually test it by adding an h2 tag to a post and then give the h2 tag an id that matches the id that add-anchor-links will generate on the a tag. Then view the published post to confirm that the inserted a tag does not have an id added because the id is already on the h2 tag.

Below is the output that was generated before this pull request (notice the duplicate id="faq"):

<h2 id="faq"><a href="#faq" aria-hidden="true" class="aal_anchor"  id="faq"><svg>...</svg></a>faq</h2>

With the pull request the output will be:

<h2 id="faq"><a href="#faq" aria-hidden="true" class="aal_anchor"><svg>...</svg></a>faq</h2>

You can also confirm that the id is still added to the a tag when a different id is on the h2 tag or when the h2 tag does not have an id.

Made the id grouping (in the regex) optional so that this still works if the <h1-6> tags do not have an id.
@vyskoczilova
Copy link
Owner

Thanks again! Sorry for the delay, but I'm finishing my PhD and I'm running out of my time. Will check it in October.

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