diff --git a/package-lock.json b/package-lock.json index 674e5183..8e745121 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "fuzzaldrin-plus": "^0.6.0", "highlight.js": "^11.7.0", "inferno": "^7.4.11", - "marked": "^3.0.8", + "marked": "^9.1.3", + "marked-highlight": "^2.0.6", "neovim": "^4.10.0", "ts-node": "^10.4.0", "twgl.js": "^4.21.2" @@ -5803,14 +5804,22 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" }, "node_modules/marked": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/marked/-/marked-3.0.8.tgz", - "integrity": "sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==", + "version": "9.1.3", + "resolved": "https://registry.npmjs.org/marked/-/marked-9.1.3.tgz", + "integrity": "sha512-XPU/J7GzU/n4voCSw1VYggtr3W5C2OeGkwEbe5PIQdA8thaie2Qw+fig6iNidKNDokTNcyR4OE9fMK14P6rqPg==", "bin": { - "marked": "bin/marked" + "marked": "bin/marked.js" }, "engines": { - "node": ">= 12" + "node": ">= 16" + } + }, + "node_modules/marked-highlight": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/marked-highlight/-/marked-highlight-2.0.6.tgz", + "integrity": "sha512-xjA/C6xgXAfkkYg+YHnxdjmgFyTDtqqu8KbZiqh+COJ7PuzR15kqa+rPrs6pf/2jExXtG1jyCFUHmv9s0Bi/dQ==", + "peerDependencies": { + "marked": ">=4 <10" } }, "node_modules/marky": { diff --git a/package.json b/package.json index e4e74768..b7e5b1e8 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "fuzzaldrin-plus": "^0.6.0", "highlight.js": "^11.7.0", "inferno": "^7.4.11", - "marked": "^3.0.8", + "marked": "^9.1.3", + "marked-highlight": "^2.0.6", "neovim": "^4.10.0", "ts-node": "^10.4.0", "twgl.js": "^4.21.2" diff --git a/src/common/fs-watch.ts b/src/common/fs-watch.ts index b5f9426b..bb8207a7 100644 --- a/src/common/fs-watch.ts +++ b/src/common/fs-watch.ts @@ -20,7 +20,9 @@ const getRealPath = async (path: string) => { const watchDir = (path: string) => fs.watch(path, (_, file) => { - const fullpath = join(path, file) + // TODO(smolck): Any chance this file! is gonna fail? + // Didn't use to be type string | null so idk + const fullpath = join(path, file!) watchers.emit(fullpath) }) diff --git a/src/renderer/components/extensions/highlight.ts b/src/renderer/components/extensions/highlight.ts new file mode 100644 index 00000000..9278cca6 --- /dev/null +++ b/src/renderer/components/extensions/highlight.ts @@ -0,0 +1,19 @@ +import { Marked } from 'marked' +import { markedHighlight } from 'marked-highlight' +import hljs from 'highlight.js' + +// See example in https://www.npmjs.com/package/marked-highlight +const marked = new Marked( + markedHighlight({ + langPrefix: 'hljs language-', + highlight(code, lang) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + return hljs.highlight(code, { language }).value; + } + }) + ); + +export const stringToMarkdown = (s: string): string => + // @ts-ignore the above `marked` isn't async but the parse has a return + // type of string | Promise just in case so TS is annoyed + marked.parse(s) \ No newline at end of file diff --git a/src/renderer/components/extensions/lsp-hover.tsx b/src/renderer/components/extensions/lsp-hover.tsx index c65ac383..41f4edb8 100644 --- a/src/renderer/components/extensions/lsp-hover.tsx +++ b/src/renderer/components/extensions/lsp-hover.tsx @@ -5,23 +5,10 @@ import { debounce } from '../../../common/utils' import Overlay from '../overlay' import { docStyle } from '../../ui/styles' import { cursor } from '../../cursor' -import { parse as stringToMarkdown, setOptions } from 'marked' import { render } from 'inferno' import { cell, size as workspaceSize } from '../../workspace' import { Events } from '../../../common/ipc' - -setOptions({ - highlight: (code, lang, _) => { - const hljs = require('highlight.js/lib/core') - hljs.registerLanguage( - lang, - require(`highlight.js/lib/languages/${lang}.js`) - ) - - const highlightedCode = hljs.highlight(code, { language: lang }).value - return highlightedCode - }, -}) +import { stringToMarkdown } from './highlight' interface ShowParams { hoverHeight: number