fix: handling rerender in sandbox mode

This commit is contained in:
Knut Sveidqvist 2022-01-22 12:36:18 +01:00
parent a73b291c4f
commit e3e9c67f5b
3 changed files with 35 additions and 19 deletions

View File

@ -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) {}

View File

@ -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) {

View File

@ -233,24 +233,23 @@ const render = function (id, _txt, cb, container) {
}
// let d3Iframe;
let root;
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');
}
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
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
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')