Skip to content

Commit 882ba03

Browse files
committed
fix: handling diagram width in sandbox mode
1 parent 46cdacf commit 882ba03

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

cypress/platform/knsv.html

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
font-family: 'Arial';
1515
/* font-size: 18px !important; */
1616
width: 100%;
17+
display: flex;
1718
}
1819
h1 { color: grey;}
1920
.mermaid2,.mermaid3 {
@@ -25,7 +26,7 @@
2526
</style>
2627
</head>
2728
<body>
28-
<div class="mermaid2" style="width: 100%;">
29+
<div class="mermaid2" style="width: 50%;">
2930
pie title Pets adopted by volunteers
3031
"Dogs" : 386
3132
"Cats" : 85
@@ -63,7 +64,7 @@
6364
commit
6465
merge newbranch
6566
</div>
66-
<div class="mermaid2" style="width: 100%;">
67+
<div class="mermaid" style="width: 50%;">
6768
sequenceDiagram
6869
participant a as Alice
6970
participant j as John
@@ -75,8 +76,7 @@
7576
links a: {"Dashboard": "https://www.contoso.com/dashboard", "On-Call": "https://www.contoso.com/oncall"}
7677
link a: Contacts @ https://contacts.contoso.com/[email protected]
7778
a->>j: Hello John, how are you?
78-
j-->>a: Great!
79-
</div>
79+
j-->>a: Great! </div>
8080
<div class="mermaid2" style="width: 100%;">
8181
journey
8282
title My working day
@@ -144,21 +144,13 @@
144144
a1-->a2-->a3
145145
end
146146
</div>
147-
<div class="mermaid2" style="width: 100%;">
148-
flowchart TB
149-
Function-->URL
147+
<div class="mermaid" style="width: 50%;">
148+
flowchart LR
149+
Function-->URL-->A-->B-->C
150150
click Function clickByFlow "Add a div"
151151
click URL "https://mermaid-js.github.io/mermaid/#/" "Visit <strong>mermaid docs</strong>" _blank
152152
</div>
153153
<div class="mermaid2" style="width: 100%;">
154-
classDiagram-v2
155-
class Test
156-
class ShapeLink
157-
link ShapeLink "https://mermaid-js.github.io/mermaid/#/" "This is a tooltip for a link"
158-
class ShapeCallback
159-
callback ShapeCallback "clickByClass" "This is a tooltip for a callback"
160-
</div>
161-
<div class="mermaid" style="width: 100%;">
162154
gantt
163155
dateFormat YYYY-MM-DD
164156
axisFormat %d/%m
@@ -264,7 +256,12 @@
264256
htmlLabels: true,
265257
},
266258
// gantt: { axisFormat: '%m/%d/%Y' },
267-
sequence: { actorFontFamily: 'courier', actorMargin: 50, showSequenceNumbers: false },
259+
sequence: {
260+
actorFontFamily: 'courier',
261+
actorMargin: 50,
262+
showSequenceNumbers: false,
263+
// forceMenus: true,
264+
},
268265
// sequenceDiagram: { actorMargin: 300, forceMenus: false }, // deprecated
269266
// fontFamily: '"times", sans-serif',
270267
// fontFamily: 'courier',
@@ -276,7 +273,7 @@
276273
logLevel: 0,
277274
fontSize: 18,
278275
curve: 'cardinal',
279-
securityLevel: 'sandbox',
276+
// securityLevel: 'sandbox',
280277
// themeVariables: {relationLabelColor: 'red'}
281278
});
282279
function callback() {

src/dagre-wrapper/nodes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import intersect from './intersect/index.js';
66
import createLabel from './createLabel';
77
import note from './shapes/note';
88
import { parseMember } from '../diagrams/class/svgDraw';
9-
import { evaluate } from '../diagrams/common/common';
9+
import { evaluate, sanitizeText as sanitize } from '../diagrams/common/common';
10+
11+
const sanitizeText = (txt) => sanitize(txt, getConfig());
1012

1113
const question = (parent, node) => {
1214
const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true);

src/diagrams/class/classDb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export const setLink = function (ids, linkStr, target) {
216216
if (config.securityLevel === 'sandbox') {
217217
classes[id].linkTarget = '_top';
218218
} else if (typeof target === 'string') {
219-
classes[id].linkTarget = target;
219+
classes[id].linkTarget = sanitizeText(target);
220220
} else {
221221
classes[id].linkTarget = '_blank';
222222
}

src/mermaidAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ const render = function (id, _txt, cb, container) {
528528
let width = '100%';
529529
let height = '100%';
530530
if (svgEl) {
531-
width = svgEl.viewBox.baseVal.width + 'px';
531+
// width = svgEl.viewBox.baseVal.width + 'px';
532532
height = svgEl.viewBox.baseVal.height + 'px';
533533
}
534534
svgCode = `<iframe style="width:${width};height:${height};border:0;margin:0;" src="data:text/html;base64,${btoa(

0 commit comments

Comments
 (0)