Skip to content

Commit

Permalink
Deployed b50170f with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Apr 21, 2024
1 parent ace035c commit 7d066ef
Show file tree
Hide file tree
Showing 7 changed files with 642 additions and 375 deletions.
100 changes: 70 additions & 30 deletions LM7805/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@
if (!diagrams.length) {
return;
}
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.2.3/mermaid.esm.min.mjs")).default;
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
const parser = new DOMParser();

mermaid.initialize({
maxTextSize: 100000,
Expand All @@ -451,39 +452,52 @@
let _nextMermaidId = 0;

function makeMermaidImage(svg) {
const img = document.createElement('img');
const maxWidth = svg.match(/max-width: (\d+)/);
if (maxWidth && maxWidth[1]) {
const width = parseInt(maxWidth[1]);
if (width && !Number.isNaN(width) && Number.isFinite(width)) {
img.width = width;
}
const img = document.createElement("img");
const doc = parser.parseFromString(svg, "image/svg+xml");
const svgEl = doc.querySelector("svg");
const { maxWidth } = svgEl?.style || {};
const firstTitle = doc.querySelector("title");
const firstDesc = doc.querySelector("desc");

img.setAttribute("src", `data:image/svg+xml,${encodeURIComponent(svg)}`);
if (maxWidth) {
img.width = parseInt(maxWidth);
}
if (firstTitle) {
img.setAttribute("alt", firstTitle.textContent);
}
if (firstDesc) {
const caption = document.createElement("figcaption");
caption.className = "sr-only";
caption.textContent = firstDesc.textContent;
return [img, caption];
}
img.setAttribute('src', `data:image/svg+xml,${encodeURIComponent(svg)}`);
return img;
return [img];
}

async function makeMermaidError(text) {
let errorMessage = '';
let errorMessage = "";
try {
await mermaid.parse(text);
} catch (err) {
errorMessage = `${err}`;
}

const result = document.createElement('details');
const summary = document.createElement('summary');
const pre = document.createElement('pre');
const code = document.createElement('code');
const result = document.createElement("details");
result.className = 'jp-RenderedMermaid-Details';
const summary = document.createElement("summary");
summary.className = 'jp-RenderedMermaid-Summary';
const pre = document.createElement("pre");
const code = document.createElement("code");
code.innerText = text;
pre.appendChild(code);
summary.appendChild(pre);
result.appendChild(summary);

const warning = document.createElement('pre');
const warning = document.createElement("pre");
warning.innerText = errorMessage;
result.appendChild(warning);
return result;
return [result];
}

async function renderOneMarmaid(src) {
Expand All @@ -493,49 +507,75 @@
const el = document.createElement("div");
el.style.visibility = "hidden";
document.body.appendChild(el);
let result = null;
let results = null;
let output = null;
try {
const { svg } = await mermaid.render(id, raw, el);
result = makeMermaidImage(svg);
results = makeMermaidImage(svg);
output = document.createElement("figure");
results.map(output.appendChild, output);
} catch (err) {
parent.classList.add("jp-mod-warning");
result = await makeMermaidError(raw);
results = await makeMermaidError(raw);
output = results[0];
} finally {
el.remove();
}
parent.classList.add("jp-RenderedMermaid");
parent.appendChild(result);
parent.appendChild(output);
}

void Promise.all([...diagrams].map(renderOneMarmaid));
});
</script>
<style>
.jp-RenderedMarkdown .jp-Mermaid:not(.jp-RenderedMermaid) {
.jp-Mermaid:not(.jp-RenderedMermaid) {
display: none;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning {

.jp-RenderedMermaid {
overflow: auto;
display: flex;
}

.jp-RenderedMermaid.jp-mod-warning {
width: auto;
padding: 10px;
padding: 0.5em;
margin-top: 0.5em;
border: var(--jp-border-width) solid var(--jp-warn-color2);
border-radius: var(--jp-border-radius);
color: var(--jp-ui-font-color1);
font-size: var(--jp-ui-font-size1);
white-space: pre-wrap;
word-wrap: break-word;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning details > pre {

.jp-RenderedMermaid figure {
margin: 0;
overflow: auto;
max-width: 100%;
}

.jp-RenderedMermaid img {
max-width: 100%;
}

.jp-RenderedMermaid-Details > pre {
margin-top: 1em;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary {

.jp-RenderedMermaid-Summary {
color: var(--jp-warn-color2);
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary > pre {
display: inline-block;
}
.jp-RenderedMermaid > .mermaid {

.jp-RenderedMermaid:not(.jp-mod-warning) pre {
display: none;
}

.jp-RenderedMermaid-Summary > pre {
display: inline-block;
white-space: normal;
}
</style>
<!-- End of mermaid configuration --><div class="jupyter-wrapper">
<div class="jp-Notebook" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
Expand Down
100 changes: 70 additions & 30 deletions UA78L05/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@
if (!diagrams.length) {
return;
}
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.2.3/mermaid.esm.min.mjs")).default;
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
const parser = new DOMParser();

mermaid.initialize({
maxTextSize: 100000,
Expand All @@ -433,39 +434,52 @@
let _nextMermaidId = 0;

function makeMermaidImage(svg) {
const img = document.createElement('img');
const maxWidth = svg.match(/max-width: (\d+)/);
if (maxWidth && maxWidth[1]) {
const width = parseInt(maxWidth[1]);
if (width && !Number.isNaN(width) && Number.isFinite(width)) {
img.width = width;
}
const img = document.createElement("img");
const doc = parser.parseFromString(svg, "image/svg+xml");
const svgEl = doc.querySelector("svg");
const { maxWidth } = svgEl?.style || {};
const firstTitle = doc.querySelector("title");
const firstDesc = doc.querySelector("desc");

img.setAttribute("src", `data:image/svg+xml,${encodeURIComponent(svg)}`);
if (maxWidth) {
img.width = parseInt(maxWidth);
}
if (firstTitle) {
img.setAttribute("alt", firstTitle.textContent);
}
if (firstDesc) {
const caption = document.createElement("figcaption");
caption.className = "sr-only";
caption.textContent = firstDesc.textContent;
return [img, caption];
}
img.setAttribute('src', `data:image/svg+xml,${encodeURIComponent(svg)}`);
return img;
return [img];
}

async function makeMermaidError(text) {
let errorMessage = '';
let errorMessage = "";
try {
await mermaid.parse(text);
} catch (err) {
errorMessage = `${err}`;
}

const result = document.createElement('details');
const summary = document.createElement('summary');
const pre = document.createElement('pre');
const code = document.createElement('code');
const result = document.createElement("details");
result.className = 'jp-RenderedMermaid-Details';
const summary = document.createElement("summary");
summary.className = 'jp-RenderedMermaid-Summary';
const pre = document.createElement("pre");
const code = document.createElement("code");
code.innerText = text;
pre.appendChild(code);
summary.appendChild(pre);
result.appendChild(summary);

const warning = document.createElement('pre');
const warning = document.createElement("pre");
warning.innerText = errorMessage;
result.appendChild(warning);
return result;
return [result];
}

async function renderOneMarmaid(src) {
Expand All @@ -475,49 +489,75 @@
const el = document.createElement("div");
el.style.visibility = "hidden";
document.body.appendChild(el);
let result = null;
let results = null;
let output = null;
try {
const { svg } = await mermaid.render(id, raw, el);
result = makeMermaidImage(svg);
results = makeMermaidImage(svg);
output = document.createElement("figure");
results.map(output.appendChild, output);
} catch (err) {
parent.classList.add("jp-mod-warning");
result = await makeMermaidError(raw);
results = await makeMermaidError(raw);
output = results[0];
} finally {
el.remove();
}
parent.classList.add("jp-RenderedMermaid");
parent.appendChild(result);
parent.appendChild(output);
}

void Promise.all([...diagrams].map(renderOneMarmaid));
});
</script>
<style>
.jp-RenderedMarkdown .jp-Mermaid:not(.jp-RenderedMermaid) {
.jp-Mermaid:not(.jp-RenderedMermaid) {
display: none;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning {

.jp-RenderedMermaid {
overflow: auto;
display: flex;
}

.jp-RenderedMermaid.jp-mod-warning {
width: auto;
padding: 10px;
padding: 0.5em;
margin-top: 0.5em;
border: var(--jp-border-width) solid var(--jp-warn-color2);
border-radius: var(--jp-border-radius);
color: var(--jp-ui-font-color1);
font-size: var(--jp-ui-font-size1);
white-space: pre-wrap;
word-wrap: break-word;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning details > pre {

.jp-RenderedMermaid figure {
margin: 0;
overflow: auto;
max-width: 100%;
}

.jp-RenderedMermaid img {
max-width: 100%;
}

.jp-RenderedMermaid-Details > pre {
margin-top: 1em;
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary {

.jp-RenderedMermaid-Summary {
color: var(--jp-warn-color2);
}
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary > pre {
display: inline-block;
}
.jp-RenderedMermaid > .mermaid {

.jp-RenderedMermaid:not(.jp-mod-warning) pre {
display: none;
}

.jp-RenderedMermaid-Summary > pre {
display: inline-block;
white-space: normal;
}
</style>
<!-- End of mermaid configuration --><div class="jupyter-wrapper">
<div class="jp-Notebook" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
Expand Down
Loading

0 comments on commit 7d066ef

Please sign in to comment.