|
|
@@ -259,14 +259,19 @@ export function normalizeHeaderMetaFlexLayoutForDocx(html: string): string {
|
|
|
/**
|
|
|
* 印章在预览为 absolute 居中叠字;Word 不认 absolute,改为 float + 负 margin 浮于后续文字上方。
|
|
|
* 供方/需方标题下的横向分割线(border-bottom)保持不变。
|
|
|
+ *
|
|
|
+ * 注意:必须去掉原标签里的自闭合 `/`,否则会生成非法的 `<img ... / style="...">`,
|
|
|
+ * html-to-docx 会解析失败并导出空白文档。
|
|
|
*/
|
|
|
export function normalizeSealImagesForDocx(html: string): string {
|
|
|
- return html.replace(/<img\b([^>]*alt\s*=\s*["']印章["'][^>]*)>/gi, (_full, attrs: string) => {
|
|
|
- let rest = String(attrs).replace(/\s*style\s*=\s*(["'])[\s\S]*?\1/i, '')
|
|
|
- rest = rest.replace(/\s*style\s*=\s*{[^}]*}/i, '')
|
|
|
+ return html.replace(/<img\b([^>]*alt\s*=\s*["']印章["'][^>]*)\/?\s*>/gi, (_full, attrs: string) => {
|
|
|
+ let rest = String(attrs)
|
|
|
+ .replace(/\s*style\s*=\s*(["'])[\s\S]*?\1/i, '')
|
|
|
+ .replace(/\/\s*$/g, '')
|
|
|
+ .trim()
|
|
|
const style =
|
|
|
'float:left;width:140px;height:140px;margin:4px 12px -120px 24px;opacity:0.85;'
|
|
|
- return `<img${rest} style="${style}">`
|
|
|
+ return `<img ${rest} style="${style}" />`
|
|
|
})
|
|
|
}
|
|
|
|