From df40ac2db0271abfd5b0e56b310f30f4376752c8 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 11 May 2017 19:54:36 +0800 Subject: [PATCH] bugfix: fix Marked highlihgt option --- src/resources/hoedown.js | 10 +++++++--- src/resources/markdown-it.js | 1 - src/resources/marked.js | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/resources/hoedown.js b/src/resources/hoedown.js index b04cc59d..6a71810f 100644 --- a/src/resources/hoedown.js +++ b/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; + } } }); diff --git a/src/resources/markdown-it.js b/src/resources/markdown-it.js index 3d728356..a2ecacf1 100644 --- a/src/resources/markdown-it.js +++ b/src/resources/markdown-it.js @@ -46,7 +46,6 @@ var mdit = window.markdownit({ } else { return hljs.highlightAuto(str).value; } - return ''; } }); diff --git a/src/resources/marked.js b/src/resources/marked.js index d43a7774..5d9c53be 100644 --- a/src/resources/marked.js +++ b/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; + } } });