Description
When multiple headings contain the same text, the Anchors plugin generates duplicate id attributes for those headings.
For example, the following content:
<h2>Link Examples</h2>
<h3>Hover and Focus</h3>
<p>...</p>
<h2>Image Examples</h2>
<h3>Hover and Focus</h3>
<p>...</p>
is rendered as:
<h2 id="link-examples">Link Examples</h2>
<h3 id="hover-and-focus">Hover and Focus</h3>
<p>...</p>
<h2 id="image-examples">Image Examples</h2>
<h3 id="hover-and-focus">Hover and Focus</h3>
<p>...</p>
This results in duplicate IDs within the same document, which produces invalid HTML and breaks anchor navigation, table-of-contents links, etc. that relies on unique IDs.
The plugin should ensure generated IDs are unique, similar to how it is done for entry slugs. For example by appending a numeric suffix (hover-and-focus, hover-and-focus-2, etc.) when duplicate heading text is encountered.
Steps to reproduce
- Create content containing two or more headings with identical text.
- Render the content using the Anchors plugin.
- Inspect the generated HTML.
- Observe that each identical heading receives the same id attribute.
Additional info
- Craft version: N/A
- PHP version: N/A
- Database driver & version: N/A
- Plugins & versions: Anchors
Description
When multiple headings contain the same text, the Anchors plugin generates duplicate id attributes for those headings.
For example, the following content:
is rendered as:
This results in duplicate IDs within the same document, which produces invalid HTML and breaks anchor navigation, table-of-contents links, etc. that relies on unique IDs.
The plugin should ensure generated IDs are unique, similar to how it is done for entry slugs. For example by appending a numeric suffix (hover-and-focus, hover-and-focus-2, etc.) when duplicate heading text is encountered.
Steps to reproduce
Additional info