chore: Use string templates

This commit is contained in:
Sidharth Vinod 2024-06-20 22:48:28 +05:30
parent 81d8b9d02e
commit 9bbd3cab3c
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
3 changed files with 6 additions and 11 deletions

View File

@ -98,7 +98,7 @@ mermaid.initialize(config);
#### Defined in
[mermaidAPI.ts:636](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L636)
[mermaidAPI.ts:634](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L634)
## Functions
@ -129,7 +129,7 @@ Return the last node appended
#### Defined in
[mermaidAPI.ts:278](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L278)
[mermaidAPI.ts:276](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L276)
---
@ -280,4 +280,4 @@ Remove any existing elements from the given document
#### Defined in
[mermaidAPI.ts:328](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L328)
[mermaidAPI.ts:326](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L326)

View File

@ -200,11 +200,8 @@ describe('mermaidAPI', () => {
});
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 expectedSrc = 'src="data:text/html;charset=UTF-8;base64,' + base64encodedSrc + '"';
const base64encodedSrc = toBase64(`<body style="margin:0">${inputSvgCode}</body>`);
const expectedSrc = `src="data:text/html;charset=UTF-8;base64,${base64encodedSrc}"`;
const result = putIntoIFrame(inputSvgCode);
expect(result).toContain(expectedSrc);
});

View File

@ -254,9 +254,7 @@ export const putIntoIFrame = (svgCode = '', svgElement?: D3Element): string => {
const height = svgElement?.viewBox?.baseVal?.height
? svgElement.viewBox.baseVal.height + 'px'
: 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}">
${IFRAME_NOT_SUPPORTED_MSG}
</iframe>`;