Highlight.js 代码高亮显示
Highlight.js 是一个轻量级代码高亮 js 包,使用简单方便
安装
bash
npm install highlight.js
yarn add highlight.js
流行语言高亮: common
js
import hljs from 'highlight.js/lib/common'
import 'highlight.js/styles/monokai-sublime.css'
onMount(() => {
hljs.highlightAll()
})
自定义语言高亮: core
typescript
import hljs from 'highlight.js/lib/core'
import 'highlight.js/styles/monokai-sublime.css'
import xml from 'highlight.js/lib/languages/xml'
hljs.registerLanguage('xml', xml)
onMount(() => {
hljs.highlightAll()
})
加载全部语言
typescript
import hljs from 'highlight.js'
import 'highlight.js/styles/monokai-sublime.css'
onMount(() => {
hljs.highlightAll()
})