import { addFilePrefix } from './common'
export function normalizeRichTextImages(content = '', imageStyle = '') {
const normalizedStyle = String(imageStyle || '').trim()
return String(content || '').replace(/
]*)>/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
? `
`
: `
`
})
}