Skip to content

Commit 7af7c7b

Browse files
committed
Preserve existing IDs for admonition toggle items
Update togglebutton.js to use an admonition's existing ID if present, instead of always generating a new one. This prevents overwriting custom or pre-existing IDs on admonition elements.
1 parent f4f9e43 commit 7af7c7b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

sphinx_togglebutton/_static/togglebutton.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ var initToggleItems = () => {
1717
itemsToToggle.forEach((item, index) => {
1818
if (item.classList.contains("admonition")) {
1919
// If it's an admonition block, then we'll add a button inside
20-
// Generate unique IDs for this item
21-
var toggleID = `toggle-${index}`;
20+
// Generate unique IDs for this item,
21+
// IF AND ONLY IF THE ITEM DOESN'T ALREADY HAVE AN ID
22+
if (!item.id) {
23+
var toggleID = `toggle-${index}`;
24+
} else {
25+
var toggleID = item.id;
26+
}
2227
var buttonID = `button-${toggleID}`;
2328

2429
item.setAttribute("id", toggleID);

0 commit comments

Comments
 (0)