Skip to content

Commit 29a7368

Browse files
committed
fix: Make processMermaidDiagrams globally accessible for fallback
- Made processMermaidDiagrams available on window object - Fixed fallback script to use window.processMermaidDiagrams - Added delay check for mermaid loading - Ensures diagrams process correctly in all scenarios
1 parent e471a02 commit 29a7368

1 file changed

Lines changed: 52 additions & 43 deletions

File tree

docs_site/_layouts/default.html

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,15 @@
769769
});
770770
}
771771

772-
// Function to process Mermaid diagrams
773-
function processMermaidDiagrams() {
772+
// Make processMermaidDiagrams available globally
773+
window.processMermaidDiagrams = function() {
774774
console.log('Processing Mermaid diagrams...');
775775

776+
if (typeof mermaid === 'undefined') {
777+
console.error('Mermaid not loaded yet');
778+
return;
779+
}
780+
776781
// Find all code blocks with mermaid language
777782
const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]');
778783

@@ -844,13 +849,15 @@
844849
console.log('No Mermaid diagrams found to render');
845850
}
846851
}
847-
}
852+
};
848853

849854
// Wait for everything to be ready
850855
function initMermaid() {
851856
// Wait a bit for Jekyll/Kramdown to finish processing
852857
setTimeout(() => {
853-
processMermaidDiagrams();
858+
if (typeof window.processMermaidDiagrams === 'function') {
859+
window.processMermaidDiagrams();
860+
}
854861
}, 300); // Increased delay for GitHub Pages
855862
}
856863

@@ -865,45 +872,47 @@
865872

866873
<!-- Fallback: Load Mermaid via regular script if module fails -->
867874
<script>
868-
// If mermaid wasn't loaded via module, load it via regular script
869-
if (typeof window.mermaid === 'undefined') {
870-
console.log('Loading Mermaid via fallback script...');
871-
const script = document.createElement('script');
872-
script.src = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
873-
script.onload = function() {
874-
mermaid.initialize({
875-
startOnLoad: false,
876-
theme: 'default',
877-
securityLevel: 'loose',
878-
flowchart: { useMaxWidth: true },
879-
sequence: { useMaxWidth: true },
880-
gantt: { useMaxWidth: true }
881-
});
882-
window.mermaid = mermaid;
883-
884-
// Process diagrams after loading
885-
setTimeout(() => {
886-
if (typeof processMermaidDiagrams === 'function') {
887-
processMermaidDiagrams();
888-
} else {
889-
// Fallback processing
890-
const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]');
891-
mermaidBlocks.forEach((block) => {
892-
const preElement = block.parentElement;
893-
if (preElement && preElement.tagName === 'PRE') {
894-
const mermaidCode = block.textContent || block.innerText;
895-
const mermaidDiv = document.createElement('div');
896-
mermaidDiv.className = 'mermaid';
897-
mermaidDiv.textContent = mermaidCode;
898-
preElement.parentNode.replaceChild(mermaidDiv, preElement);
899-
}
900-
});
901-
mermaid.run();
902-
}
903-
}, 100);
904-
};
905-
document.head.appendChild(script);
906-
}
875+
// Check if mermaid was loaded after a delay
876+
setTimeout(() => {
877+
if (typeof window.mermaid === 'undefined') {
878+
console.log('Loading Mermaid via fallback script...');
879+
const script = document.createElement('script');
880+
script.src = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
881+
script.onload = function() {
882+
mermaid.initialize({
883+
startOnLoad: false,
884+
theme: 'default',
885+
securityLevel: 'loose',
886+
flowchart: { useMaxWidth: true },
887+
sequence: { useMaxWidth: true },
888+
gantt: { useMaxWidth: true }
889+
});
890+
window.mermaid = mermaid;
891+
892+
// Process diagrams after loading
893+
setTimeout(() => {
894+
if (typeof window.processMermaidDiagrams === 'function') {
895+
window.processMermaidDiagrams();
896+
} else {
897+
// Fallback processing
898+
const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]');
899+
mermaidBlocks.forEach((block) => {
900+
const preElement = block.parentElement;
901+
if (preElement && preElement.tagName === 'PRE') {
902+
const mermaidCode = block.textContent || block.innerText;
903+
const mermaidDiv = document.createElement('div');
904+
mermaidDiv.className = 'mermaid';
905+
mermaidDiv.textContent = mermaidCode;
906+
preElement.parentNode.replaceChild(mermaidDiv, preElement);
907+
}
908+
});
909+
mermaid.run();
910+
}
911+
}, 200);
912+
};
913+
document.head.appendChild(script);
914+
}
915+
}, 500);
907916
</script>
908917
</body>
909918

0 commit comments

Comments
 (0)