Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions integrations/code/media/mermaid.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 - 2022 Knut Sveidqvist

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3,607 changes: 3,607 additions & 0 deletions integrations/code/media/mermaid.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions integrations/code/media/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,21 @@
vertical-align: super;
}

.md-typeset .mermaid {
display: flex;
justify-content: center;
max-width: 100%;
overflow-x: auto;
}

.md-typeset .mermaid svg {
max-width: 100%;
height: auto;
}

</style>
<script nonce="__NONCE__" src="__KATEX__"></script>
<script nonce="__NONCE__" src="__MERMAID__"></script>
</head>
<body
dir="ltr"
Expand All @@ -68,6 +81,7 @@
let renderedUri = null;
let fragmentTarget = null;
let pendingFragment = null;
let mermaidId = 0;
const uiStateByUri = new Map();

function updateColorScheme() {
Expand All @@ -76,6 +90,7 @@
document.body.classList.contains("vscode-high-contrast")
? "slate"
: "default";
void renderMermaid();
}

updateColorScheme();
Expand Down Expand Up @@ -274,6 +289,38 @@
}
}

async function renderMermaid() {
const nodes = [...preview.querySelectorAll(".mermaid")];
if (!window.mermaid || !nodes.length) return;

const dark =
document.body.classList.contains("vscode-dark") ||
document.body.classList.contains("vscode-high-contrast");
window.mermaid.initialize({
startOnLoad: false,
securityLevel: "strict",
theme: dark ? "dark" : "default",
});

for (const node of nodes) {
const source = node.dataset.mermaidSource || node.textContent.trim();
if (!source) continue;
node.dataset.mermaidSource = source;

try {
const result = await window.mermaid.render(
`preview-mermaid-${++mermaidId}`,
source,
node,
);
node.innerHTML = result.svg;
result.bindFunctions?.(node);
} catch {
// Keep the source visible when Mermaid cannot parse a diagram.
}
}
}

function utf8Index(text) {
const encoder = new TextEncoder();
const bytes = [];
Expand Down Expand Up @@ -506,6 +553,7 @@
...sanitizeHtml(decorateHtml(update.html, update.mappings || [])),
);
typesetMath();
void renderMermaid();
restoreUiState(renderedUri);
revealPendingFragment();
if (activeSourceOffset !== null) {
Expand Down
Loading