perf: 优化 pr 代码

This commit is contained in:
ChenZhaoYu
2023-02-15 13:26:02 +08:00
parent b2977d8c44
commit 79eeb51537
10 changed files with 132 additions and 76 deletions

View File

@@ -0,0 +1,15 @@
import type { App, Directive } from 'vue'
import hljs from 'highlight.js'
const regexp = /^(?:\s{4}|\t).+/gm
export default function setupHighlightDirective(app: App) {
const highLightDirective: Directive<HTMLElement> = {
mounted(el: HTMLElement) {
if (el.textContent?.indexOf(' = ') !== -1 || el.textContent.match(regexp))
hljs.highlightBlock(el)
},
}
app.directive('highlight', highLightDirective)
}