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
17 changes: 17 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import markdownItGithubAlerts from "markdown-it-github-alerts";

export default function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("_assets");
eleventyConfig.addPassthroughCopy({
"node_modules/mermaid/dist/mermaid.min.js": "_assets/mermaid.min.js",
});

const markdownLibrary = markdownIt({ html: true, typographer: true })
.use(markdownItGithubAlerts)
.use(markdownItAnchor, { level: [2, 3, 4] });
eleventyConfig.setLibrary("md", markdownLibrary);

// Mermaid fenced code blocks render as <pre class="mermaid"> instead of
// highlighted code, which is the markup mermaid.js looks for in the
// browser to replace with an inline SVG diagram.
const defaultFenceRenderer = markdownLibrary.renderer.rules.fence.bind(
markdownLibrary.renderer.rules,
);
markdownLibrary.renderer.rules.fence = (tokens, idx, options, env, self) => {
const token = tokens[idx];
if (token.info.trim() === "mermaid") {
return `<pre class="mermaid">${markdownLibrary.utils.escapeHtml(token.content)}</pre>\n`;
}
return defaultFenceRenderer(tokens, idx, options, env, self);
};

// Builds a collapsed, non-printing table of contents from the h2-h4
// headings (and their anchor ids, added by markdown-it-anchor above)
// found in a page's rendered content.
Expand Down
6 changes: 6 additions & 0 deletions _assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ pre {
margin-bottom: 0;
}

pre.mermaid[data-processed] {
background-color: transparent;
padding: 0;
text-align: center;
}

@media print {
nav,
.noprint {
Expand Down
4 changes: 4 additions & 0 deletions _includes/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
</span>
</p>
</footer>
<script src="/_assets/mermaid.min.js"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
Comment on lines +54 to +57

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mermaid.min.js is about 5.5 MB and is requested on every page, including the ones with no diagram. Optional: load it only when the page has one.

Suggested change
<script src="/_assets/mermaid.min.js"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
<script>
if (document.querySelector("pre.mermaid")) {
const script = document.createElement("script");
script.src = "/_assets/mermaid.min.js";
script.onload = () => {
mermaid.initialize({ startOnLoad: false });
mermaid.run();
};
document.head.appendChild(script);
}
</script>

</body>
</html>
Loading
Loading