mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-01 12:41:43 +08:00
Adds font-awesome when is required (mermaid). (#913)
* Adds font-awesome when is required (mermaid). * applied suggestions * format with prettier vscode plugin
This commit is contained in:
parent
b42d28f7a8
commit
cdb17e8573
1 changed files with 19 additions and 0 deletions
|
@ -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 `<pre><code>${e.message}</code></pre>`;
|
||||
|
|
Loading…
Reference in a new issue