Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fix(mermaid): fix styles and escape html
Browse files Browse the repository at this point in the history
fixes: #389
fixes: #391
  • Loading branch information
hiroppy committed Feb 18, 2021
1 parent dd4a940 commit 0adf1f9
Show file tree
Hide file tree
Showing 8 changed files with 1,358 additions and 35 deletions.
5 changes: 5 additions & 0 deletions packages/client/assets/style/customize.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
max-width: var(--base-max-width);
min-width: 320px;
z-index: 2;
width: 100vw; /* for mermaid */
}

.slide-background {
Expand Down Expand Up @@ -67,3 +68,7 @@
height: var(--qr-code-image-size);
margin: 0 auto;
}

.mermaid {
width: 100%;
}
29 changes: 13 additions & 16 deletions packages/client/src/setup/Mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ export class Mermaid {
constructor() {
mermaid.initialize({
startOnLoad: false,
er: {
useMaxWidth: false,
},
flowchart: {
useMaxWidth: false,
},
sequence: {
useMaxWidth: false,
},
gantt: {
useMaxWidth: false,
},
});
}

getElms() {
return document.querySelectorAll('.mermaid');
}

encode(elm) {
const encodedString = `data:image/svg+xml;base64,${btoa(elm.innerHTML)}`;

elm.innerHTML = ''; // delete svg
Object.assign(elm.style, {
visibility: 'initial',
background: `url(${encodedString})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
margin: '0 auto',
});
}

init() {
const elms = this.getElms();

Expand All @@ -33,7 +32,6 @@ export class Mermaid {
});

mermaid.init();
// this.encode(elm);
});
}

Expand All @@ -57,12 +55,11 @@ export class Mermaid {

elm.removeAttribute('data-processed');

mermaid.init();
Object.assign(elm.style, {
visibility: 'initial',
});

// this.encode(elm);
mermaid.init();
}
}
}
Loading

0 comments on commit 0adf1f9

Please sign in to comment.