mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Backport #23178 fix #23153 Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: delvh <leon@kske.dev>
This commit is contained in:
		| @@ -37,14 +37,10 @@ export async function renderMermaid() { | ||||
|       continue; | ||||
|     } | ||||
|  | ||||
|     let valid; | ||||
|     try { | ||||
|       valid = mermaid.parse(source); | ||||
|       await mermaid.parse(source); | ||||
|     } catch (err) { | ||||
|       displayError(el, err); | ||||
|     } | ||||
|  | ||||
|     if (!valid) { | ||||
|       el.closest('pre').classList.remove('is-loading'); | ||||
|       continue; | ||||
|     } | ||||
| @@ -52,22 +48,25 @@ export async function renderMermaid() { | ||||
|     try { | ||||
|       // can't use bindFunctions here because we can't cross the iframe boundary. This | ||||
|       // means js-based interactions won't work but they aren't intended to work either | ||||
|       mermaid.mermaidAPI.render('mermaid', source, (svgStr) => { | ||||
|         const heightStr = (svgStr.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3]; | ||||
|         if (!heightStr) return displayError(el, new Error('Could not determine chart height')); | ||||
|         const iframe = document.createElement('iframe'); | ||||
|         iframe.classList.add('markup-render'); | ||||
|         iframe.sandbox = 'allow-scripts'; | ||||
|         iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`; | ||||
|         iframe.srcdoc = `<html><head><style>${iframeCss}</style></head><body>${svgStr}</body></html>`; | ||||
|         const mermaidBlock = document.createElement('div'); | ||||
|         mermaidBlock.classList.add('mermaid-block'); | ||||
|         mermaidBlock.append(iframe); | ||||
|         const btn = makeCodeCopyButton(); | ||||
|         btn.setAttribute('data-clipboard-text', source); | ||||
|         mermaidBlock.append(btn); | ||||
|         el.closest('pre').replaceWith(mermaidBlock); | ||||
|       }); | ||||
|       const {svg} = await mermaid.render('mermaid', source); | ||||
|       const heightStr = (svg.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3]; | ||||
|       if (!heightStr) return displayError(el, new Error('Could not determine chart height')); | ||||
|  | ||||
|       const iframe = document.createElement('iframe'); | ||||
|       iframe.classList.add('markup-render'); | ||||
|       iframe.sandbox = 'allow-scripts'; | ||||
|       iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`; | ||||
|       iframe.srcdoc = `<html><head><style>${iframeCss}</style></head><body>${svg}</body></html>`; | ||||
|  | ||||
|       const mermaidBlock = document.createElement('div'); | ||||
|       mermaidBlock.classList.add('mermaid-block'); | ||||
|       mermaidBlock.append(iframe); | ||||
|  | ||||
|       const btn = makeCodeCopyButton(); | ||||
|       btn.setAttribute('data-clipboard-text', source); | ||||
|  | ||||
|       mermaidBlock.append(btn); | ||||
|       el.closest('pre').replaceWith(mermaidBlock); | ||||
|     } catch (err) { | ||||
|       displayError(el, err); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Giteabot
					Giteabot