-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 修复 `API` 版本 HTML 会被渲染的问题[#146] * chore: version 2.8.1
- Loading branch information
1 parent
2c509c3
commit 21fb4f8
Showing
8 changed files
with
73 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { App, Directive } from 'vue' | ||
import hljs from 'highlight.js' | ||
import { includeCode } from '@/utils/format' | ||
|
||
hljs.configure({ ignoreUnescapedHTML: true }) | ||
|
||
function highlightCode(el: HTMLElement) { | ||
if (includeCode(el.textContent)) | ||
hljs.highlightBlock(el) | ||
} | ||
|
||
export default function setupHighlightDirective(app: App) { | ||
const highLightDirective: Directive<HTMLElement> = { | ||
mounted(el: HTMLElement) { | ||
highlightCode(el) | ||
}, | ||
updated(el: HTMLElement) { | ||
highlightCode(el) | ||
}, | ||
} | ||
|
||
app.directive('highlight', highLightDirective) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export function setupDirectives() {} | ||
import type { App } from 'vue' | ||
import setupHighlightDirective from './highlight' | ||
|
||
export function setupDirectives(app: App) { | ||
setupHighlightDirective(app) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 转义 HTML 字符 | ||
export function encodeHTML(source: string) { | ||
return source | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
|
||
// 判断是否为代码块 | ||
export function includeCode(text: string | null | undefined) { | ||
const regexp = /^(?:\s{4}|\t).+/gm | ||
return !!(text?.includes(' = ') || text?.match(regexp)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters