diff --git a/assets/js/cell/markdown/mermaid.js b/assets/js/cell/markdown/mermaid.js index bc6957e9b..81f145b8f 100644 --- a/assets/js/cell/markdown/mermaid.js +++ b/assets/js/cell/markdown/mermaid.js @@ -3,6 +3,8 @@ let getId = () => `mermaid-graph-${idCount++}`; let mermaidInitialized = false; +const fontAwesomeVersion = "5.15.4"; + function importMermaid() { return import( /* webpackChunkName: "mermaid" */ @@ -16,9 +18,26 @@ function importMermaid() { }); } +const maybeInjectFontAwesome = (value) => { + const fontAwesomeUrl = `https://cdnjs.cloudflare.com/ajax/libs/font-awesome/${fontAwesomeVersion}/css/all.min.css`; + if ( + value.includes("fa:") && + !document.querySelector(`link[href="${fontAwesomeUrl}"]`) + ) { + const link = document.createElement("link"); + link.rel = "stylesheet"; + link.type = "text/css"; + link.href = fontAwesomeUrl; + document.head.appendChild(link); + } +}; + export function renderMermaid(value) { return importMermaid().then((mermaid) => { try { + // Inject font-awesome when fa: prefix is used + maybeInjectFontAwesome(value); + return mermaid.render(getId(), value); } catch (e) { return `
${e.message}
`;