mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-11 22:16:10 +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;
|
let mermaidInitialized = false;
|
||||||
|
|
||||||
|
const fontAwesomeVersion = "5.15.4";
|
||||||
|
|
||||||
function importMermaid() {
|
function importMermaid() {
|
||||||
return import(
|
return import(
|
||||||
/* webpackChunkName: "mermaid" */
|
/* 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) {
|
export function renderMermaid(value) {
|
||||||
return importMermaid().then((mermaid) => {
|
return importMermaid().then((mermaid) => {
|
||||||
try {
|
try {
|
||||||
|
// Inject font-awesome when fa: prefix is used
|
||||||
|
maybeInjectFontAwesome(value);
|
||||||
|
|
||||||
return mermaid.render(getId(), value);
|
return mermaid.render(getId(), value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return `<pre><code>${e.message}</code></pre>`;
|
return `<pre><code>${e.message}</code></pre>`;
|
||||||
|
|
Loading…
Add table
Reference in a new issue