hexojs / hexo-renderer-markdown-it

Markdown-it is a Markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
MIT License
343 stars 60 forks source link

Support mermaid in markdown #72

Closed mythsman closed 5 years ago

mythsman commented 5 years ago

I think it would be better if hexo-render-markdown-it can support mermaid language to help us draw diagrams.

Or , is there any other way for me to use mermaid in my article gracefully ?

Thank you!

yoshinorin commented 5 years ago

@mythsman IMHO, we will not implement mermaid.js support. Because, markdown-it plugins not supported mermaid.js

If you want to use mermaid.js you should implement it by customizing your theme. I wrote an example below.

First

Please add below code in your theme.

<% if (post.enableMermaidjs) { %>
  <script async src="https://unpkg.com/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
  <script>
  window.onload = function () {
    mermaid.initialize({startOnLoad:true});
  };
  </script>
<% } %>

Second

Hexo can define a variable to each post. Please add enableMermaidjs front-matter to you post which you want to use mermaid.js.

---
title: Hello World
date: 2013/7/13 20:46:25
enableMermaidjs: true    // you can define original variable to each post
---

You can control which post to use mermaid.js if you implement above code.

mythsman commented 5 years ago

@YoshinoriN Thank you for your suggestion which helps me a lot :smile: