Skip to content

Commit

Permalink
markdown code render fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed May 1, 2024
1 parent 65ffb0e commit 74e368d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "witsy",
"productName": "Witsy",
"version": "1.4.2",
"version": "1.4.3",
"description": "Witsy: desktop AI assistant",
"repository": {
"type": "git",
Expand Down
20 changes: 11 additions & 9 deletions src/main/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<pre class="hljs"><code class="hljs">';
try {
let code = '<pre class="hljs"><code class="hljs">';
if (lang && hljs.getLanguage(lang)) {
code += hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
code += '</code></pre>';
code += '<p><a href="#" onclick="navigator.clipboard.writeText(window.api.base64.decode(\'' + Buffer.from(str).toString('base64') + '\'));';
code += 'this.innerHTML = \'Copied!\'; setTimeout(() => this.innerHTML = \'Copy code\', 1000); return false;" class="copy">Copy code</a></p>';
return code;
} catch (error) {
console.log(error)
} else {
code += hljs.highlightAuto(str).value;
}
code += '</code></pre>';
code += '<p><a href="#" onclick="navigator.clipboard.writeText(window.api.base64.decode(\'' + Buffer.from(str).toString('base64') + '\'));';
code += 'this.innerHTML = \'Copied!\'; setTimeout(() => this.innerHTML = \'Copy code\', 1000); return false;" class="copy">Copy code</a></p>';
return code;
} catch (error) {
console.log(error)
}
return '' // use external default escaping
}
Expand Down

0 comments on commit 74e368d

Please sign in to comment.