Skip to content

Commit 17d39dd

Browse files
committed
Assign ids even to blocks whose hash is duplicated
To avoid breaking the localStorage backing for the editors, which is keyed by ID.
1 parent 3c5ec7c commit 17d39dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/render_html.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ function maybeSplitInlineCode(html) {
5454
const seenIDs = Object.create(null)
5555
function anchor(token) {
5656
let id = token.hashID
57-
if (!id || id in seenIDs) return ""
57+
if (id in seenIDs) for (let i = 1;; i++) {
58+
let ext = id + "_" + i
59+
if (!(ext in seenIDs)) { id = ext; break }
60+
}
5861
seenIDs[id] = true
5962
return `<a class="${id.charAt(0)}_ident" id="${id}" href="#${id}" tabindex="-1" role="presentation"></a>`
6063
}

0 commit comments

Comments
 (0)