Skip to content

Add Mermaid diagrams to slides with proper rendering#1

Merged
stiffneckjim merged 6 commits into
developfrom
feature/add-network-diagrams
May 25, 2026
Merged

Add Mermaid diagrams to slides with proper rendering#1
stiffneckjim merged 6 commits into
developfrom
feature/add-network-diagrams

Conversation

@stiffneckjim
Copy link
Copy Markdown
Contributor

Summary

Fixes Mermaid diagram rendering by properly transforming code blocks from Marp's language-mermaid format to the mermaid class format that Mermaid.js expects.

Changes

  • inject-mermaid.mjs: Added JSDOM-based transformation to convert <code class="language-mermaid"> blocks to <pre class="mermaid"> elements
  • package.json: Added jsdom as a dev dependency for HTML parsing
  • slides.md: Includes 3 Mermaid diagrams showing network architecture, DNS flow, and demo steps

Problem & Solution

Marp was rendering fenced code blocks with mermaid language as <code class="language-mermaid"> inside <pre> tags, but Mermaid.js looks for elements with the mermaid class directly. The injection script now:

  1. Parses the generated HTML with JSDOM
  2. Finds all language-mermaid code blocks
  3. Replaces them with <pre class="mermaid"> elements
  4. Injects Mermaid.js library and initializes rendering

Testing

  • Run pnpm build to verify transformation message
  • Serve with pnpm serve and check http://127.0.0.1:8001 to see rendered diagrams

- Add network architecture diagram showing Pi-hole placement
- Add DNS query flow sequence diagram (blocked vs allowed)
- Add demo flow diagram
- Enhance key takeaways and add questions slide with resources
- Add http-server as dev dependency on port 8001
- Add 'serve' and 'preview' npm scripts for local browsing
- Add marp.config.js with Mermaid configuration
- Create inject-mermaid.mjs post-build script to load mermaid.js CDN
- Update build.mjs to run Mermaid injection after Marp build
- Diagrams now render properly in browser
Copilot AI review requested due to automatic review settings May 25, 2026 15:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Marp-based slide deck build pipeline so Mermaid diagrams render correctly by post-processing the generated HTML and injecting Mermaid.js, and it expands the deck content with several Mermaid diagrams.

Changes:

  • Added an HTML post-processing script (scripts/inject-mermaid.mjs) that converts Marp’s code.language-mermaid blocks into pre.mermaid blocks and injects Mermaid.js initialization.
  • Updated the build pipeline to run Marp with marp.config.js and then run the Mermaid injection step.
  • Added Mermaid diagrams to slides.md and introduced http-server-based preview scripts.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
slides.md Adds Mermaid-based diagrams and updates slide content/structure.
scripts/inject-mermaid.mjs Implements JSDOM-based HTML transformation + Mermaid.js injection.
scripts/build.mjs Runs Marp with a config file and executes the Mermaid injection step after build.
package.json Adds jsdom + http-server and introduces serve/preview scripts.
marp.config.js Enables HTML/markdown HTML and adds Mermaid configuration.
pnpm-lock.yaml Locks new dependencies (jsdom, http-server, transitive deps).
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json Outdated
"@marp-team/marp-cli": "^4.1.0"
"@marp-team/marp-cli": "^4.1.0",
"http-server": "^14.1.0",
"jsdom": "^29.1.1"
Comment thread scripts/inject-mermaid.mjs Outdated
Comment on lines +34 to +37
if (!html.includes('mermaid.min.js')) {
const mermaidScript = `<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"><\/script>
<script>mermaid.initialize({ startOnLoad: true, theme: 'default' }); mermaid.contentLoaded();<\/script>
</body>`;
Comment thread scripts/inject-mermaid.mjs Outdated
Comment on lines +34 to +43
if (!html.includes('mermaid.min.js')) {
const mermaidScript = `<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"><\/script>
<script>mermaid.initialize({ startOnLoad: true, theme: 'default' }); mermaid.contentLoaded();<\/script>
</body>`;

html = html.replace('</body>', mermaidScript);
}

writeFileSync(outputFile, html, 'utf-8');
console.log(`✓ Transformed ${codeBlocks.length} mermaid code block(s) and injected library`);
Comment thread package.json
Comment on lines 9 to 14
"scripts": {
"dev": "pnpm exec marp slides.md --server --allow-local-files",
"build": "node scripts/build.mjs",
"serve": "http-server dist -p 8001 -o",
"preview": "pnpm build && pnpm serve",
"export": "pnpm exec marp slides.md --pdf --allow-local-files --output dist/slides.pdf",
Copy link
Copy Markdown
Contributor Author

@stiffneckjim stiffneckjim left a comment

Choose a reason for hiding this comment

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

LGTM

@stiffneckjim stiffneckjim merged commit 3496d77 into develop May 25, 2026
@stiffneckjim stiffneckjim deleted the feature/add-network-diagrams branch May 25, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants