浏览代码

Add syntax content option

simov 3 年之前
父节点
当前提交
0b008b2e1b
共有 4 个文件被更改,包括 17 次插入8 次删除
  1. 1 1
      background/inject.js
  2. 4 0
      background/storage.js
  3. 11 7
      content/index.js
  4. 1 0
      popup/index.js

+ 1 - 1
background/inject.js

@@ -28,7 +28,7 @@ md.inject = ({storage: {state}}) => (id) => {
     target: {tabId: id},
     files: [
       '/vendor/mithril.min.js',
-      '/vendor/prism.min.js',
+      state.content.syntax && '/vendor/prism.min.js',
       state.content.emoji && '/content/emoji.js',
       state.content.mermaid && ['/vendor/mermaid.min.js', '/content/mermaid.js'],
       '/content/index.js',

+ 4 - 0
background/storage.js

@@ -54,6 +54,7 @@ md.storage.defaults = (compilers) => {
       mathjax: false,
       autoreload: false,
       mermaid: false,
+      syntax: true,
     },
     origins: {
       'file://': {
@@ -123,4 +124,7 @@ md.storage.migrations = (state) => {
   if (state.marked.smartLists !== undefined) {
     delete state.marked.smartLists
   }
+  if (state.content.syntax === undefined) {
+    state.content.syntax = true
+  }
 }

+ 11 - 7
content/index.js

@@ -47,7 +47,9 @@ var oncreate = {
       m.redraw()
     }
 
-    setTimeout(() => Prism.highlightAll(), 20)
+    if (state.content.syntax) {
+      setTimeout(() => Prism.highlightAll(), 20)
+    }
 
     anchors()
   },
@@ -91,12 +93,14 @@ function mount () {
           }))
           $('body').classList.add(`_theme-${state.theme}`)
 
-          var prism = ['github-dark', 'markdown-retro', 'sakura-vader', 'water-dark']
-            .includes(state.theme) ? 'prism-okaidia' : 'prism'
-          dom.push(m('link#_prism', {
-            rel: 'stylesheet', type: 'text/css',
-            href: chrome.runtime.getURL(`/vendor/${prism}.min.css`),
-          }))
+          if (state.content.syntax) {
+            var prism = ['github-dark', 'markdown-retro', 'sakura-vader', 'water-dark']
+              .includes(state.theme) ? 'prism-okaidia' : 'prism'
+            dom.push(m('link#_prism', {
+              rel: 'stylesheet', type: 'text/css',
+              href: chrome.runtime.getURL(`/vendor/${prism}.min.css`),
+            }))
+          }
         }
         if (state.html) {
           dom.push(m('#_html', {oncreate: oncreate.html,

+ 1 - 0
popup/index.js

@@ -55,6 +55,7 @@ var state = {
       toc: 'Generate Table of Contents',
       mathjax: 'Render MathJax formulas',
       mermaid: 'Mermaid diagrams',
+      syntax: 'Syntax highlighting for fenced code blocks',
     }
   }
 }