Skip to content

Instantly share code, notes, and snippets.

@tuboihirokidesu
Last active December 26, 2025 01:00
Show Gist options
  • Select an option

  • Save tuboihirokidesu/94296be83e9d314bc5b65af6d4884e2e to your computer and use it in GitHub Desktop.

Select an option

Save tuboihirokidesu/94296be83e9d314bc5b65af6d4884e2e to your computer and use it in GitHub Desktop.
md-to-pdf の Mermaidをサポートのためのカスタム設定ファイル
// md-to-pdf Mermaid設定
// marked extensions形式でMermaidコードブロックを処理
module.exports = {
// marked extensionsを使用
marked_extensions: [
{
name: "mermaid",
level: "block",
start(src) {
return src.match(/```mermaid/)?.index;
},
tokenizer(src) {
const match = src.match(/^```mermaid\n([\s\S]*?)```/);
if (match) {
return {
type: "mermaid",
raw: match[0],
text: match[1].trim(),
};
}
},
renderer(token) {
return `<pre class="mermaid">${token.text}</pre>`;
},
},
],
// MermaidをCDNから読み込む
script: [
{ url: "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js" },
// Mermaid初期化スクリプト
{
content: `
mermaid.initialize({
startOnLoad: false,
theme: 'default',
securityLevel: 'loose'
});
(async () => {
await mermaid.run();
})();
`,
},
],
// スタイル設定
css: `
.mermaid {
text-align: center;
background: white;
padding: 1rem;
}
`,
pdf_options: {
format: "A4",
margin: {
top: "20mm",
bottom: "20mm",
left: "15mm",
right: "15mm",
},
printBackground: true,
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment