Duplicate Heading Contents Don't Get Unique IDs

RESOLVED FIXED

Status

developer.mozilla.org
Editing
P2
normal
RESOLVED FIXED
5 years ago
4 years ago

People

(Reporter: ghost@ethertank.jp, Assigned: davidwalsh)

Tracking

Details

(Whiteboard: [mentor=openjck])

(Reporter)

Description

5 years ago
User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11

Steps to reproduce:

If you write as follows, the same id attribute is applied to two heading element.

INPUT:
  <h3>Result</h3>
  <h3>Result</h3>


Actual results:

OUTPUT:
  <h3 id="Result">Result</h3>
  <h3 id="Result">Result</h3>

ID attribute is duplicate. This will kill TOC.
Many TOC was already dead.


Expected results:

Example:
  <h3 id="Result_1">Result</h3>
  <h3 id="Result_2">Result</h3>

This is just one example.
Anyway, this will need to be addressed.
(Assignee)

Updated

5 years ago
Assignee: nobody → dwalsh
Summary: Duplicated ID → Duplicate Heading Contents Don't Get Unique IDs
Identical header contents are turned into identical IDs. I think this is also the way it was in MindTouch. Might be handy to add some code that adds numbers to successive (but not the first) duplicates, and try to avoid breaking existing links.
Hmm, actually, there's code here that *used* to generate totally unique IDs for headers (eg. sect1, sect2, sect3, ...):

    https://github.com/mozilla/kuma/blob/master/apps/wiki/content.py#L301

But, I think we revised that to use slugified header text for IDs to more closely match MindTouch and try not to break links. Sounds like the thing to do here is to further revise the slugifying code to track known IDs and append numbers when an ID has already been used
(Assignee)

Comment 3

5 years ago
I've done that but it's still a bit awkward due to what's commented as "# Pass 1".  My current implementation is here:

https://github.com/darkwing/kuma/compare/duplicate-id-819912

The remaining issue is that on the first pass, everything is correct:

<h2 id="Result">Result</h2>
<h2 id="Result_1">Result</h2>
<h2 id="Result_2">Result</h2>

But on the next edit, the IDs will become:

<h2 id="Result">Result</h2>
<h2 id="Result_3">Result</h2>
<h2 id="Result_4">Result</h2>

The "#Pass 1" routine puts those names into the known_ids set, so they appear taken in routine 2.

Getting around this will simply take some thought.
Duplicate of this bug: 780595
Often the case in API documentation:
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIContentPrefService2#Parameters
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P2
Duplicate of this bug: 855555
Whiteboard: [mentor=openjck]
Duplicate of this bug: 958557
Duplicate of this bug: 976757
I have been looking into this one, and think it could be solved with a simple tweak to Walsh's solution. I just have to test it first :)
I have opened a pull request regarding this issue.
https://github.com/mozilla/kuma/pull/2088

Comment 11

4 years ago
Commits pushed to master at https://github.com/mozilla/kuma

https://github.com/mozilla/kuma/commit/f281169c4e4af02214cbb77f2820b82a1586a0da
Fix bug 819912 - Duplicate heading IDs

https://github.com/mozilla/kuma/commit/b72e47bef55f1ec14234cece0d5aef5ee1c9adc8
Merge pull request #2088 from mediocrity/heading_unique_ids

Fix bug 819912 - Duplicate heading IDs

Updated

4 years ago
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED

Comment 12

4 years ago
Commits pushed to search-filter-api at https://github.com/mozilla/kuma

https://github.com/mozilla/kuma/commit/f281169c4e4af02214cbb77f2820b82a1586a0da
Fix bug 819912 - Duplicate heading IDs

https://github.com/mozilla/kuma/commit/b72e47bef55f1ec14234cece0d5aef5ee1c9adc8
Merge pull request #2088 from mediocrity/heading_unique_ids
You need to log in before you can comment on or make changes to this bug.