2020-02-12 00:27:34 +02:00
|
|
|
/* global mermaid */
|
|
|
|
|
|
|
|
function mermaidReady() {
|
|
|
|
return typeof mermaid !== 'undefined';
|
|
|
|
}
|
|
|
|
|
|
|
|
function mermaidInit() {
|
|
|
|
// Mermaid's wonderful API has two init methods: init() and initialize().
|
|
|
|
// init() is deprectated but works, and initialize() is recommended but doesn't
|
|
|
|
// work, so let's use init() for now.
|
2020-03-04 03:55:48 +02:00
|
|
|
if (mermaidReady()) {
|
|
|
|
try {
|
|
|
|
mermaid.init();
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Mermaid error', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resetting elements size - see mermaid.ts
|
|
|
|
const elements = document.getElementsByClassName('mermaid');
|
|
|
|
for (const element of elements) {
|
2020-05-09 17:21:01 +02:00
|
|
|
element.style.width = 'fit-content';
|
2020-03-04 03:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-12 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('joplin-noteDidUpdate', () => {
|
|
|
|
mermaidInit();
|
|
|
|
});
|
|
|
|
|
|
|
|
const initIID_ = setInterval(() => {
|
|
|
|
const isReady = mermaidReady();
|
|
|
|
if (isReady) {
|
|
|
|
clearInterval(initIID_);
|
|
|
|
mermaidInit();
|
|
|
|
}
|
|
|
|
}, 100);
|