chore: initial import

This commit is contained in:
liangjian
2026-06-29 09:42:53 +08:00
commit 9fea127de1
241 changed files with 82767 additions and 0 deletions

20
utils/rich-text.js Normal file
View File

@@ -0,0 +1,20 @@
import { addFilePrefix } from './common'
export function normalizeRichTextImages(content = '', imageStyle = '') {
const normalizedStyle = String(imageStyle || '').trim()
return String(content || '').replace(/<img\b([^>]*)>/gi, (match, rawAttrs = '') => {
const attrs = String(rawAttrs || '')
.replace(/\swidth\s*=\s*(['"]).*?\1/gi, '')
.replace(/\sheight\s*=\s*(['"]).*?\1/gi, '')
.replace(/\sstyle\s*=\s*(['"]).*?\1/gi, '')
const normalizedAttrs = attrs.replace(/\ssrc\s*=\s*(['"])(.*?)\1/gi, (srcMatch, quote, srcValue = '') => {
const normalizedSrc = addFilePrefix(srcValue)
return normalizedSrc ? ` src=${quote}${normalizedSrc}${quote}` : srcMatch
})
return normalizedStyle
? `<img${normalizedAttrs} style="${normalizedStyle}" />`
: `<img${normalizedAttrs} />`
})
}