mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-16 18:54:12 +01:00
Format
This commit is contained in:
@@ -69,7 +69,7 @@ vi.mock('stylis', () => {
|
|||||||
import { compile, serialize } from 'stylis';
|
import { compile, serialize } from 'stylis';
|
||||||
import { decodeEntities, encodeEntities } from './utils.js';
|
import { decodeEntities, encodeEntities } from './utils.js';
|
||||||
import { Diagram } from './Diagram.js';
|
import { Diagram } from './Diagram.js';
|
||||||
import {toBase64} from './utils/base64.js';
|
import { toBase64 } from './utils/base64.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see https://vitest.dev/guide/mocking.html Mock part of a module
|
* @see https://vitest.dev/guide/mocking.html Mock part of a module
|
||||||
@@ -200,8 +200,12 @@ describe('mermaidAPI', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sets src to base64 version of <body style="IFRAME_SVG_BODY_STYLE">svgCode<//body>', () => {
|
it('sets src to base64 version of <body style="IFRAME_SVG_BODY_STYLE">svgCode<//body>', () => {
|
||||||
const base64encodedSrc = toBase64('<body style="' + 'margin:0' + '">' + inputSvgCode + '</body>');
|
const base64encodedSrc = toBase64(
|
||||||
const expectedRegExp = new RegExp('src="data:text/html;charset=UTF-8;base64,' + base64encodedSrc + '"');
|
'<body style="' + 'margin:0' + '">' + inputSvgCode + '</body>'
|
||||||
|
);
|
||||||
|
const expectedRegExp = new RegExp(
|
||||||
|
'src="data:text/html;charset=UTF-8;base64,' + base64encodedSrc + '"'
|
||||||
|
);
|
||||||
|
|
||||||
const result = putIntoIFrame(inputSvgCode);
|
const result = putIntoIFrame(inputSvgCode);
|
||||||
expect(result).toMatch(expectedRegExp);
|
expect(result).toMatch(expectedRegExp);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility.
|
|||||||
import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.js';
|
import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.js';
|
||||||
import { preprocessDiagram } from './preprocess.js';
|
import { preprocessDiagram } from './preprocess.js';
|
||||||
import { decodeEntities } from './utils.js';
|
import { decodeEntities } from './utils.js';
|
||||||
import {toBase64} from './utils/base64.js';
|
import { toBase64 } from './utils/base64.js';
|
||||||
|
|
||||||
const MAX_TEXTLENGTH = 50_000;
|
const MAX_TEXTLENGTH = 50_000;
|
||||||
const MAX_TEXTLENGTH_EXCEEDED_MSG =
|
const MAX_TEXTLENGTH_EXCEEDED_MSG =
|
||||||
@@ -255,7 +255,9 @@ export const putIntoIFrame = (svgCode = '', svgElement?: D3Element): string => {
|
|||||||
const height = svgElement?.viewBox?.baseVal?.height
|
const height = svgElement?.viewBox?.baseVal?.height
|
||||||
? svgElement.viewBox.baseVal.height + 'px'
|
? svgElement.viewBox.baseVal.height + 'px'
|
||||||
: IFRAME_HEIGHT;
|
: IFRAME_HEIGHT;
|
||||||
const base64encodedSrc = toBase64('<body style="' + IFRAME_BODY_STYLE + '">' + svgCode + '</body>');
|
const base64encodedSrc = toBase64(
|
||||||
|
'<body style="' + IFRAME_BODY_STYLE + '">' + svgCode + '</body>'
|
||||||
|
);
|
||||||
return `<iframe style="width:${IFRAME_WIDTH};height:${height};${IFRAME_STYLES}" src="data:text/html;charset=UTF-8;base64,${base64encodedSrc}" sandbox="${IFRAME_SANDBOX_OPTS}">
|
return `<iframe style="width:${IFRAME_WIDTH};height:${height};${IFRAME_STYLES}" src="data:text/html;charset=UTF-8;base64,${base64encodedSrc}" sandbox="${IFRAME_SANDBOX_OPTS}">
|
||||||
${IFRAME_NOT_SUPPORTED_MSG}
|
${IFRAME_NOT_SUPPORTED_MSG}
|
||||||
</iframe>`;
|
</iframe>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user