mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	feat(share): render inline mermaid (closes #5438)
This commit is contained in:
		| @@ -29,6 +29,14 @@ async function formatCodeBlocks() { | ||||
|     await formatCodeBlocks($("#content")); | ||||
| } | ||||
|  | ||||
| async function setupTextNote() { | ||||
|     formatCodeBlocks(); | ||||
|     applyMath(); | ||||
|  | ||||
|     const setupMermaid = (await import("./share/mermaid.js")).default; | ||||
|     setupMermaid(); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Fetch note with given ID from backend | ||||
|  * | ||||
| @@ -50,8 +58,7 @@ document.addEventListener( | ||||
|         const noteType = determineNoteType(); | ||||
|  | ||||
|         if (noteType === "text") { | ||||
|             formatCodeBlocks(); | ||||
|             applyMath(); | ||||
|             setupTextNote(); | ||||
|         } | ||||
|  | ||||
|         const toggleMenuButton = document.getElementById("toggleMenuButton"); | ||||
|   | ||||
							
								
								
									
										17
									
								
								apps/client/src/share/mermaid.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								apps/client/src/share/mermaid.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| import mermaid from "mermaid"; | ||||
|  | ||||
| export default function setupMermaid() { | ||||
|     for (const codeBlock of document.querySelectorAll("#content pre code.language-mermaid")) { | ||||
|         const parentPre = codeBlock.parentElement; | ||||
|         if (!parentPre) { | ||||
|             continue; | ||||
|         } | ||||
|  | ||||
|         const mermaidDiv = document.createElement("div"); | ||||
|         mermaidDiv.classList.add("mermaid"); | ||||
|         mermaidDiv.innerHTML = codeBlock.innerHTML; | ||||
|         parentPre.replaceWith(mermaidDiv); | ||||
|     } | ||||
|  | ||||
|     mermaid.init(); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user