Skip to content

Commit

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

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

function makeMermaidImage(svg) {
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];
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;
}
}
return [img];
img.setAttribute('src', `data:image/svg+xml,${encodeURIComponent(svg)}`);
return img;
}

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

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");
const result = document.createElement('details');
const summary = document.createElement('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 @@ -507,74 +493,48 @@
const el = document.createElement("div");
el.style.visibility = "hidden";
document.body.appendChild(el);
let results = null;
let output = null;
let result = null;
try {
const { svg } = await mermaid.render(id, raw, el);
results = makeMermaidImage(svg);
output = document.createElement("figure");
results.map(output.appendChild, output);
result = makeMermaidImage(svg);
} catch (err) {
parent.classList.add("jp-mod-warning");
results = await makeMermaidError(raw);
output = results[0];
result = await makeMermaidError(raw);
} finally {
el.remove();
}
parent.classList.add("jp-RenderedMermaid");
parent.appendChild(output);
parent.appendChild(result);
}

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

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

.jp-RenderedMermaid.jp-mod-warning {
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning {
width: auto;
padding: 0.5em;
margin-top: 0.5em;
padding: 10px;
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-RenderedMermaid figure {
margin: 0;
overflow: auto;
max-width: 100%;
}

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

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

.jp-RenderedMermaid-Summary {
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary {
color: var(--jp-warn-color2);
}

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

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

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

function makeMermaidImage(svg) {
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];
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;
}
}
return [img];
img.setAttribute('src', `data:image/svg+xml,${encodeURIComponent(svg)}`);
return img;
}

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

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");
const result = document.createElement('details');
const summary = document.createElement('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 @@ -489,74 +475,48 @@
const el = document.createElement("div");
el.style.visibility = "hidden";
document.body.appendChild(el);
let results = null;
let output = null;
let result = null;
try {
const { svg } = await mermaid.render(id, raw, el);
results = makeMermaidImage(svg);
output = document.createElement("figure");
results.map(output.appendChild, output);
result = makeMermaidImage(svg);
} catch (err) {
parent.classList.add("jp-mod-warning");
results = await makeMermaidError(raw);
output = results[0];
result = await makeMermaidError(raw);
} finally {
el.remove();
}
parent.classList.add("jp-RenderedMermaid");
parent.appendChild(output);
parent.appendChild(result);
}

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

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

.jp-RenderedMermaid.jp-mod-warning {
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning {
width: auto;
padding: 0.5em;
margin-top: 0.5em;
padding: 10px;
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-RenderedMermaid figure {
margin: 0;
overflow: auto;
max-width: 100%;
}

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

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

.jp-RenderedMermaid-Summary {
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary {
color: var(--jp-warn-color2);
}

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

.jp-RenderedMermaid-Summary > pre {
.jp-RenderedMarkdown .jp-RenderedMermaid.jp-mod-warning summary > pre {
display: inline-block;
white-space: normal;
}
.jp-RenderedMermaid > .mermaid {
display: none;
}
</style>
<!-- End of mermaid configuration --><div class="jupyter-wrapper">
Expand Down
Loading

0 comments on commit 61ed7e6

Please sign in to comment.