瀏覽代碼

Add mermaid support

simov 4 年之前
父節點
當前提交
602a058966
共有 3 個文件被更改,包括 20 次插入0 次删除
  1. 4 0
      background/storage.js
  2. 15 0
      content/index.js
  3. 1 0
      popup/index.js

+ 4 - 0
background/storage.js

@@ -53,6 +53,7 @@ md.storage.defaults = (compilers) => {
       toc: false,
       mathjax: false,
       autoreload: false,
+      mermaid: false,
     },
     origins: {
       'file://': {
@@ -106,4 +107,7 @@ md.storage.migrations = (state) => {
   if (state.remark.pedantic !== undefined) {
     delete state.remark.pedantic
   }
+  if (state.content.mermaid === undefined) {
+    state.content.mermaid = false
+  }
 }

+ 15 - 0
content/index.js

@@ -98,6 +98,21 @@ function mount () {
               src: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js'
             }))
           }
+          if (state.content.mermaid) {
+            dom.push(m('script', {
+              src: 'https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.8.4/mermaid.min.js'
+            }))
+            dom.push(m('script', {type: 'text/javascript'}, `
+              ;(() => {
+                var timeout = setInterval(() => {
+                  if (!!(mermaid && mermaid.init)) {
+                    clearInterval(timeout)
+                    mermaid.init({}, 'code.language-mmd, code.language-mermaid')
+                  }
+                }, 50)
+              })()
+            `))
+          }
         }
       }
 

+ 1 - 0
popup/index.js

@@ -18,6 +18,7 @@ var state = {
       scroll: 'Remember scroll position',
       toc: 'Generate Table of Contents',
       mathjax: 'Render MathJax formulas',
+      mermaid: 'Mermaid diagrams',
     }
   }
 }