mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-10-31 10:54:15 +01:00 
			
		
		
		
	fix: handling rerender in sandbox mode
This commit is contained in:
		| @@ -11,10 +11,12 @@ | ||||
|         </div> | ||||
|  | ||||
|         <script src="./mermaid.js"></script> | ||||
|         <script>mermaid.init({ startOnLoad: false }); | ||||
|          mermaid.mermaidAPI.initialize(); | ||||
|         <script>mermaid.init({ startOnLoad: false, securityLevel: 'sandbox' }); | ||||
|  | ||||
|          mermaid.mermaidAPI.initialize({ securityLevel: 'sandbox' }); | ||||
|  | ||||
|          try { | ||||
|            console.log('rendering'); | ||||
|            mermaid.mermaidAPI.render('graphDiv', `>`); | ||||
|          } catch (e) {} | ||||
|  | ||||
|   | ||||
| @@ -143,8 +143,8 @@ export const addMember = function (className, member) { | ||||
|  | ||||
|     if (memberString.startsWith('<<') && memberString.endsWith('>>')) { | ||||
|       // Remove leading and trailing brackets | ||||
|       theClass.annotations.push(memberString.substring(2, memberString.length - 2)); | ||||
|       // theClass.annotations.push(sanitizeText(memberString.substring(2, memberString.length - 2))); | ||||
|       // theClass.annotations.push(memberString.substring(2, memberString.length - 2)); | ||||
|       theClass.annotations.push(sanitizeText(memberString.substring(2, memberString.length - 2))); | ||||
|     } else if (memberString.indexOf(')') > 0) { | ||||
|       theClass.methods.push(sanitizeText(memberString)); | ||||
|     } else if (memberString) { | ||||
|   | ||||
| @@ -233,7 +233,10 @@ const render = function (id, _txt, cb, container) { | ||||
|   } | ||||
|  | ||||
|   // let d3Iframe; | ||||
|   let root; | ||||
|   let root = select('body'); | ||||
|  | ||||
|   // In regular execurtion the container will be the div with a mermaid class | ||||
|   if (typeof container !== 'undefined') { | ||||
|     if (cnf.securityLevel === 'sandbox') { | ||||
|       // IF we are in sandboxed mode, we do everyting mermaid related | ||||
|       // in a sandboxed div | ||||
| @@ -245,12 +248,8 @@ const render = function (id, _txt, cb, container) { | ||||
|       // const iframeBody = ; | ||||
|       root = select(iframe.nodes()[0].contentDocument.body); | ||||
|       root.node().style.margin = 0; | ||||
|   } else { | ||||
|     root = select('body'); | ||||
|     } | ||||
|  | ||||
|   // In regular execurtion the container will be the div with a mermaid class | ||||
|   if (typeof container !== 'undefined') { | ||||
|     // A container was provided by the caller | ||||
|     container.innerHTML = ''; | ||||
|  | ||||
| @@ -310,6 +309,21 @@ const render = function (id, _txt, cb, container) { | ||||
|     // Add the tmp div used for rendering with the id `d${id}` | ||||
|     // d+id it will contain a svg with the id "id" | ||||
|  | ||||
|     if (cnf.securityLevel === 'sandbox') { | ||||
|       // IF we are in sandboxed mode, we do everyting mermaid related | ||||
|       // in a sandboxed div | ||||
|       const iframe = select('body') | ||||
|         .append('iframe') | ||||
|         .attr('id', 'i' + id) | ||||
|         .attr('style', 'width: 100%; height: 100%;') | ||||
|         .attr('sandbox', ''); | ||||
|       // const iframeBody = ; | ||||
|       root = select(iframe.nodes()[0].contentDocument.body); | ||||
|       root.node().style.margin = 0; | ||||
|     } else { | ||||
|       root = select('body'); | ||||
|     } | ||||
|  | ||||
|     // This is the temporary div | ||||
|     root | ||||
|       .append('div') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Knut Sveidqvist
					Knut Sveidqvist