Преглед изворни кода

bugfix: fix Marked highlihgt option

Le Tan пре 8 година
родитељ
комит
df40ac2db0
3 измењених фајлова са 13 додато и 6 уклоњено
  1. 7 3
      src/resources/hoedown.js
  2. 0 1
      src/resources/markdown-it.js
  3. 6 2
      src/resources/marked.js

+ 7 - 3
src/resources/hoedown.js

@@ -1,9 +1,13 @@
 var placeholder = document.getElementById('placeholder');
 
-// Use Marked to highlight code blocks.
+// Use Marked to highlight code blocks in edit mode.
 marked.setOptions({
-    highlight: function(code) {
-        return hljs.highlightAuto(code).value;
+    highlight: function(code, lang) {
+        if (lang && hljs.getLanguage(lang)) {
+            return hljs.highlight(lang, code).value;
+        } else {
+            return hljs.highlightAuto(code).value;
+        }
     }
 });
 

+ 0 - 1
src/resources/markdown-it.js

@@ -46,7 +46,6 @@ var mdit = window.markdownit({
         } else {
             return hljs.highlightAuto(str).value;
         }
-        return '';
     }
 });
 

+ 6 - 2
src/resources/marked.js

@@ -16,8 +16,12 @@ renderer.heading = function(text, level) {
 
 // Highlight.js to highlight code block
 marked.setOptions({
-    highlight: function(code) {
-        return hljs.highlightAuto(code).value;
+    highlight: function(code, lang) {
+        if (lang && hljs.getLanguage(lang)) {
+            return hljs.highlight(lang, code).value;
+        } else {
+            return hljs.highlightAuto(code).value;
+        }
     }
 });