Notion 페이지를 PDF로 변환할 때 Mermaid 다이어그램을 그림으로 보이게 만드는 방법
Notion에서 페이지를 파일로 내보낼 때, Mermaid 코드블록은 보통 코드 텍스트로 남아 있고 자동으로 렌더링되지 않는다.
따라서 PDF에도 코드 텍스트만 출력되고 다이어그램이 보이지 않는 문제가 있다.
Notion 문서를 Export 한 경우에도 Mermaid 다이어그램이 실제 그림으로 보이도록 만드는 해보자.
- Notion 페이지를 HTML로 Export
- HTML body 내부에 하단에 다음과 같은 스크립트를 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> <script> document.addEventListener('DOMContentLoaded', function () { var codeBlocks = document.querySelectorAll('code.language-Mermaid, code.language-mermaid'); codeBlocks.forEach(function (codeBlock) { var pre = codeBlock.parentElement; if (!pre) { return; } var container = document.createElement('div'); container.className = 'mermaid'; container.textContent = codeBlock.textContent; pre.replaceWith(container); }); if (window.mermaid) { mermaid.initialize({ startOnLoad: false }); mermaid.init(undefined, document.querySelectorAll('.mermaid')); } }); </script>
- HTML 파일을 브라우저를 열어서 ‘인쇄’ ‘PDF로 저장’
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.