export const formatRichText = (html) => { if (!html) return ''; let newContent = html; // 1. 移除 img 标签中的 style 属性 newContent = newContent.replace(/]*>/gi, function(match) { match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); return match; }); // 2. 强制为 img 标签添加自适应样式,并处理为块级元素 newContent = newContent.replace(/\ 标签替换为 newContent = newContent.replace(//gi, ''); return newContent; };