Skip to content

Commit

Permalink
deps: update marked (and add marked-highlight)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Oct 31, 2023
1 parent 13b885f commit 7704339
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
21 changes: 15 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/common/fs-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
19 changes: 19 additions & 0 deletions src/renderer/components/extensions/highlight.ts
Original file line number Diff line number Diff line change
@@ -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<string> just in case so TS is annoyed
marked.parse(s)
15 changes: 1 addition & 14 deletions src/renderer/components/extensions/lsp-hover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7704339

Please sign in to comment.