Skip to content

Commit 440a24e

Browse files
rorarclaude
andcommitted
debug: show DOM info when SVG not found
Adds 3 search strategies for finding the Mermaid SVG: 1. Previous sibling with .mermaid class 2. Previous sibling containing any SVG 3. Any SVG in .md-content Shows debug info on button if all fail: previous sibling tag/class and total SVG count on page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 655ba66 commit 440a24e

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

docs/javascripts/diagram-fullscreen.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,43 @@
1313
function openMermaidFullscreen(btnEl) {
1414
"use strict";
1515

16-
// Find SVG: try sibling .mermaid first, fall back to searching the whole page
16+
// Find SVG: search backwards through siblings, then fall back to page-wide search
1717
var svg = null;
18-
var mermaidEl = btnEl.previousElementSibling;
19-
while (mermaidEl) {
20-
if (mermaidEl.classList && mermaidEl.classList.contains("mermaid")) {
21-
svg = mermaidEl.querySelector("svg");
18+
19+
// Strategy 1: previous sibling with class "mermaid"
20+
var el = btnEl.previousElementSibling;
21+
while (el) {
22+
if (el.classList && el.classList.contains("mermaid")) {
23+
svg = el.querySelector("svg");
2224
break;
2325
}
24-
mermaidEl = mermaidEl.previousElementSibling;
26+
el = el.previousElementSibling;
2527
}
26-
// Fallback: find any .mermaid SVG on the page
28+
29+
// Strategy 2: previous sibling that IS an SVG or contains one
2730
if (!svg) {
28-
var allMermaid = document.querySelectorAll(".mermaid svg");
29-
if (allMermaid.length > 0) svg = allMermaid[0];
31+
el = btnEl.previousElementSibling;
32+
while (el) {
33+
if (el.tagName === "SVG") { svg = el; break; }
34+
var nested = el.querySelector("svg");
35+
if (nested) { svg = nested; break; }
36+
el = el.previousElementSibling;
37+
}
3038
}
39+
40+
// Strategy 3: any SVG in .md-content
41+
if (!svg) {
42+
var content = document.querySelector(".md-content");
43+
if (content) svg = content.querySelector("svg");
44+
}
45+
3146
if (!svg) {
32-
btnEl.textContent = "\u26A0 Diagram not ready \u2014 try again";
33-
setTimeout(function () { btnEl.textContent = "\u2922 Fullscreen"; }, 2000);
47+
// Debug: show what the previous sibling actually is
48+
var prev = btnEl.previousElementSibling;
49+
var info = prev ? (prev.tagName + "." + prev.className) : "none";
50+
var svgCount = document.querySelectorAll("svg").length;
51+
btnEl.textContent = "\u26A0 SVG not found (prev: " + info + ", svgs: " + svgCount + ")";
52+
setTimeout(function () { btnEl.textContent = "\u2922 Fullscreen"; }, 4000);
3453
return;
3554
}
3655

0 commit comments

Comments
 (0)