mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-24 15:04:53 +00:00
fix: HTML 渲染异常 (#152)
* fix: 修复 `API` 版本 HTML 会被渲染的问题[#146] * chore: version 2.8.1
This commit is contained in:
15
src/utils/format/index.ts
Normal file
15
src/utils/format/index.ts
Normal file
@@ -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))
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
function includeCode(text: string | null | undefined) {
|
||||
const regexp = /^(?:\s{4}|\t).+/gm
|
||||
return !!(text?.includes(' = ') || text?.match(regexp))
|
||||
}
|
||||
|
||||
export default includeCode
|
Reference in New Issue
Block a user