mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
36 lines
791 B
JavaScript
36 lines
791 B
JavaScript
/* 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.
|
|
if (mermaidReady()) {
|
|
try {
|
|
mermaid.init();
|
|
} catch (error) {
|
|
console.error('Mermaid error', error);
|
|
}
|
|
|
|
const elements = document.getElementsByClassName('mermaid');
|
|
for (const element of elements) {
|
|
element.style.width = '100%';
|
|
}
|
|
}
|
|
}
|
|
|
|
document.addEventListener('joplin-noteDidUpdate', () => {
|
|
mermaidInit();
|
|
});
|
|
|
|
const initIID_ = setInterval(() => {
|
|
const isReady = mermaidReady();
|
|
if (isReady) {
|
|
clearInterval(initIID_);
|
|
mermaidInit();
|
|
}
|
|
}, 100);
|