Skip to content

Commit

Permalink
Merge pull request #328 from satrong/fix-hljs
Browse files Browse the repository at this point in the history
fix: hljs fallback to plaintext if lang not support
  • Loading branch information
sugarforever authored Apr 21, 2024
2 parents 84a7952 + 4c35d33 commit 5c6e570
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
10 changes: 7 additions & 3 deletions composables/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import MarkdownIt from "markdown-it"
import MarkdownItAbbr from "markdown-it-abbr"
import MarkdownItAnchor from "markdown-it-anchor"
import MarkdownItFootnote from "markdown-it-footnote"
import MarkdownItHighlightjs from "markdown-it-highlightjs"
import MarkdownItSub from "markdown-it-sub"
import MarkdownItSup from "markdown-it-sup"
import MarkdownItTasklists from "markdown-it-task-lists"
import MarkdownItTOC from "markdown-it-toc-done-right"
import hljs from "highlight.js"

export function useMarkdown() {
return new MarkdownIt()
return new MarkdownIt({
highlight(str, lang) {
lang = hljs.getLanguage(lang) ? lang : 'plaintext'
return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value
},
})
.use(MarkdownItAbbr)
.use(MarkdownItAnchor)
.use(MarkdownItFootnote)
.use(MarkdownItHighlightjs)
.use(MarkdownItSub)
.use(MarkdownItSup)
.use(MarkdownItTasklists)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"markdown-it-abbr": "^2.0.0",
"markdown-it-anchor": "^8.6.7",
"markdown-it-footnote": "^4.0.0",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-sub": "^2.0.0",
"markdown-it-sup": "^2.0.0",
"markdown-it-task-lists": "^2.1.1",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit 5c6e570

Please sign in to comment.