瀏覽代碼

Catch unknown language error (highlight)

Sotaro KARASAWA 11 年之前
父節點
當前提交
7743659f94
共有 1 個文件被更改,包括 9 次插入4 次删除
  1. 9 4
      resource/js/crowi.js

+ 9 - 4
resource/js/crowi.js

@@ -125,15 +125,20 @@ Crowi.rendererType.markdown.prototype = {
     marked.setOptions({
       gfm: true,
       highlight: function (code, lang, callback) {
-        var result;
+        var result, hl;
         if (lang) {
-          result = hljs.highlight(lang, code);
-          return callback(null, result.value);
+          try {
+            hl = hljs.highlight(lang, code);
+            result = hl.value;
+          } catch (e) {
+            result = code;
+          }
         } else {
           //result = hljs.highlightAuto(code);
           //callback(null, result.value);
-          return callback(null, code);
+          result = code;
         }
+        return callback(null, result);
       },
       tables: true,
       breaks: true,