From 74e368db9104d0f27b238157b3073acc7f74df1d Mon Sep 17 00:00:00 2001 From: Nicolas Bonamy Date: Wed, 1 May 2024 12:53:07 -0500 Subject: [PATCH] markdown code render fix --- package.json | 2 +- src/main/markdown.ts | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 9870b666..b84a6476 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "witsy", "productName": "Witsy", - "version": "1.4.2", + "version": "1.4.3", "description": "Witsy: desktop AI assistant", "repository": { "type": "git", diff --git a/src/main/markdown.ts b/src/main/markdown.ts index 7747c9df..4455a9ea 100644 --- a/src/main/markdown.ts +++ b/src/main/markdown.ts @@ -8,17 +8,19 @@ import hljs from 'highlight.js' const mdOptions: MarkdownIt.Options = { html: true, highlight: function (str: string, lang: string) { - if (lang && hljs.getLanguage(lang)) { - try { - let code = '
';
+    try {
+      let code = '
';
+      if (lang && hljs.getLanguage(lang)) {
         code += hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
-        code += '
'; - code += '

Copy code

'; - return code; - } catch (error) { - console.log(error) + } else { + code += hljs.highlightAuto(str).value; } + code += '
'; + code += '

Copy code

'; + return code; + } catch (error) { + console.log(error) } return '' // use external default escaping }