mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-22 09:46:42 +02:00
fix: handling rerender in sandbox mode
This commit is contained in:
@@ -11,10 +11,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>mermaid.init({ startOnLoad: false });
|
<script>mermaid.init({ startOnLoad: false, securityLevel: 'sandbox' });
|
||||||
mermaid.mermaidAPI.initialize();
|
|
||||||
|
mermaid.mermaidAPI.initialize({ securityLevel: 'sandbox' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('rendering');
|
||||||
mermaid.mermaidAPI.render('graphDiv', `>`);
|
mermaid.mermaidAPI.render('graphDiv', `>`);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
@@ -143,8 +143,8 @@ export const addMember = function (className, member) {
|
|||||||
|
|
||||||
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
|
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
|
||||||
// Remove leading and trailing brackets
|
// Remove leading and trailing brackets
|
||||||
theClass.annotations.push(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)));
|
theClass.annotations.push(sanitizeText(memberString.substring(2, memberString.length - 2)));
|
||||||
} else if (memberString.indexOf(')') > 0) {
|
} else if (memberString.indexOf(')') > 0) {
|
||||||
theClass.methods.push(sanitizeText(memberString));
|
theClass.methods.push(sanitizeText(memberString));
|
||||||
} else if (memberString) {
|
} else if (memberString) {
|
||||||
|
@@ -233,24 +233,23 @@ const render = function (id, _txt, cb, container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// let d3Iframe;
|
// let d3Iframe;
|
||||||
let root;
|
let root = select('body');
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
// In regular execurtion the container will be the div with a mermaid class
|
// In regular execurtion the container will be the div with a mermaid class
|
||||||
if (typeof container !== 'undefined') {
|
if (typeof container !== 'undefined') {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// A container was provided by the caller
|
// A container was provided by the caller
|
||||||
container.innerHTML = '';
|
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}`
|
// Add the tmp div used for rendering with the id `d${id}`
|
||||||
// d+id it will contain a svg with the id "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
|
// This is the temporary div
|
||||||
root
|
root
|
||||||
.append('div')
|
.append('div')
|
||||||
|
Reference in New Issue
Block a user