|
769 | 769 | }); |
770 | 770 | } |
771 | 771 |
|
772 | | - // Function to process Mermaid diagrams |
773 | | - function processMermaidDiagrams() { |
| 772 | + // Make processMermaidDiagrams available globally |
| 773 | + window.processMermaidDiagrams = function() { |
774 | 774 | console.log('Processing Mermaid diagrams...'); |
775 | 775 |
|
| 776 | + if (typeof mermaid === 'undefined') { |
| 777 | + console.error('Mermaid not loaded yet'); |
| 778 | + return; |
| 779 | + } |
| 780 | + |
776 | 781 | // Find all code blocks with mermaid language |
777 | 782 | const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]'); |
778 | 783 |
|
|
844 | 849 | console.log('No Mermaid diagrams found to render'); |
845 | 850 | } |
846 | 851 | } |
847 | | - } |
| 852 | + }; |
848 | 853 |
|
849 | 854 | // Wait for everything to be ready |
850 | 855 | function initMermaid() { |
851 | 856 | // Wait a bit for Jekyll/Kramdown to finish processing |
852 | 857 | setTimeout(() => { |
853 | | - processMermaidDiagrams(); |
| 858 | + if (typeof window.processMermaidDiagrams === 'function') { |
| 859 | + window.processMermaidDiagrams(); |
| 860 | + } |
854 | 861 | }, 300); // Increased delay for GitHub Pages |
855 | 862 | } |
856 | 863 |
|
|
865 | 872 |
|
866 | 873 | <!-- Fallback: Load Mermaid via regular script if module fails --> |
867 | 874 | <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); |
907 | 916 | </script> |
908 | 917 | </body> |
909 | 918 |
|
|
0 commit comments