|
8 | 8 |
|
9 | 9 | <!-- Marked.js for markdown parsing - try multiple CDNs for reliability --> |
10 | 10 | <script src="https://unpkg.com/marked/marked.min.js"></script> |
| 11 | + <!-- Mermaid.js for diagram rendering --> |
| 12 | + <script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" ></script> |
11 | 13 | <script> |
12 | 14 | // Fallback if marked.js fails to load |
13 | 15 | if (typeof marked === 'undefined') { |
|
260 | 262 | font-size: 1.1rem; |
261 | 263 | } |
262 | 264 |
|
| 265 | + /* Mermaid diagram styling */ |
| 266 | + .mermaid { |
| 267 | + text-align: center; |
| 268 | + margin: 20px 0; |
| 269 | + background: white; |
| 270 | + border-radius: 8px; |
| 271 | + padding: 20px; |
| 272 | + box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
| 273 | + } |
| 274 | + |
263 | 275 | .breadcrumb { |
264 | 276 | background: #f8f9fa; |
265 | 277 | padding: 15px 40px; |
|
393 | 405 | document.title = `${title} - OSVM CLI Documentation`; |
394 | 406 | } |
395 | 407 |
|
| 408 | + // Process mermaid diagrams in the loaded content |
| 409 | + function processMermaidDiagrams() { |
| 410 | + // Find all code blocks that contain mermaid |
| 411 | + const codeBlocks = document.querySelectorAll('pre code'); |
| 412 | + |
| 413 | + codeBlocks.forEach((codeBlock, index) => { |
| 414 | + let text = codeBlock.textContent.trim(); |
| 415 | + const parentPre = codeBlock.parentElement; |
| 416 | + |
| 417 | + // Check if this is a mermaid diagram - look for mermaid language or text starting with flowchart/graph/sequenceDiagram etc. |
| 418 | + const isMermaidLang = codeBlock.className.includes('language-mermaid') || |
| 419 | + parentPre.querySelector('code[class*="language-mermaid"]'); |
| 420 | + const isMermaidContent = text.startsWith('flowchart') || |
| 421 | + text.startsWith('graph') || |
| 422 | + text.startsWith('sequenceDiagram') || |
| 423 | + text.startsWith('classDiagram') || |
| 424 | + text.startsWith('stateDiagram') || |
| 425 | + text.startsWith('pie') || |
| 426 | + text.startsWith('gantt') || |
| 427 | + text.startsWith('journey') || |
| 428 | + text.startsWith('gitgraph') || |
| 429 | + text.includes('subgraph'); |
| 430 | + |
| 431 | + if (isMermaidLang || isMermaidContent) { |
| 432 | + // Clean up the text - remove "mermaid" prefix if it exists |
| 433 | + if (text.startsWith('mermaid\n') || text.startsWith('mermaid\r\n')) { |
| 434 | + text = text.substring(text.indexOf('\n') + 1).trim(); |
| 435 | + } else if (text.startsWith('mermaidflowchart')) { |
| 436 | + text = text.substring(7); // Remove "mermaid" prefix |
| 437 | + } |
| 438 | + |
| 439 | + // Create a new div for the mermaid diagram |
| 440 | + const mermaidDiv = document.createElement('div'); |
| 441 | + mermaidDiv.className = 'mermaid'; |
| 442 | + mermaidDiv.setAttribute('id', `mermaid-${index}`); |
| 443 | + // Preserve line breaks and whitespace properly |
| 444 | + mermaidDiv.style.whiteSpace = 'pre'; |
| 445 | + mermaidDiv.textContent = text; |
| 446 | + |
| 447 | + // Replace the code block with the mermaid div |
| 448 | + parentPre.parentElement.replaceChild(mermaidDiv, parentPre); |
| 449 | + } |
| 450 | + }); |
| 451 | + |
| 452 | + // Initialize mermaid if diagrams were found and library is available |
| 453 | + const mermaidDivs = document.querySelectorAll('.mermaid'); |
| 454 | + if (mermaidDivs.length > 0) { |
| 455 | + // Initialize mermaid when library is available |
| 456 | + const initMermaid = () => { |
| 457 | + if (typeof mermaid !== 'undefined') { |
| 458 | + try { |
| 459 | + // Configure mermaid |
| 460 | + mermaid.initialize({ |
| 461 | + startOnLoad: true, |
| 462 | + theme: 'default', |
| 463 | + securityLevel: 'loose' |
| 464 | + }); |
| 465 | + } catch (error) { |
| 466 | + console.error('Error initializing mermaid:', error); |
| 467 | + } |
| 468 | + } else { |
| 469 | + console.warn('Mermaid library not available'); |
| 470 | + // Show fallback content |
| 471 | + mermaidDivs.forEach(div => { |
| 472 | + div.innerHTML = '<p><em>Mermaid diagram (requires mermaid.js)</em></p><pre style="background:#f4f4f4;padding:10px;border-radius:4px;"><code>' + div.textContent + '</code></pre>'; |
| 473 | + }); |
| 474 | + } |
| 475 | + }; |
| 476 | + |
| 477 | + // Try to initialize after a delay to ensure library is loaded |
| 478 | + setTimeout(initMermaid, 500); |
| 479 | + } |
| 480 | + } |
| 481 | + |
396 | 482 | // Load and render markdown content |
397 | 483 | async function loadDocument(docName) { |
398 | 484 | const contentElement = document.getElementById('markdown-content'); |
|
430 | 516 |
|
431 | 517 | contentElement.innerHTML = processedHtml; |
432 | 518 |
|
| 519 | + // Process mermaid diagrams |
| 520 | + processMermaidDiagrams(); |
| 521 | + |
433 | 522 | // Scroll to top |
434 | 523 | window.scrollTo(0, 0); |
435 | 524 |
|
|
0 commit comments