From 35cd8b1ce93e79370df8e3670d58707b437fc2d4 Mon Sep 17 00:00:00 2001
From: WindowBird <13870814+windows-bird@user.noreply.gitee.com>
Date: Fri, 19 Sep 2025 11:47:01 +0800
Subject: [PATCH] =?UTF-8?q?html=E6=B8=85=E9=99=A4=E8=83=8C=E6=99=AF?=
=?UTF-8?q?=E8=89=B2=E5=92=8C=E7=BA=A0=E6=AD=A3=E5=9B=BE=E7=89=87=E5=B0=BA?=
=?UTF-8?q?=E5=AF=B8=E7=9A=84=E5=87=BD=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
composables/clearnBackgroundColor.js | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 composables/clearnBackgroundColor.js
diff --git a/composables/clearnBackgroundColor.js b/composables/clearnBackgroundColor.js
new file mode 100644
index 0000000..57197af
--- /dev/null
+++ b/composables/clearnBackgroundColor.js
@@ -0,0 +1,24 @@
+/**
+ * 移除HTML内容中的背景样式并调整图片宽度
+ * @param {string} html - 需要处理的HTML字符串
+ * @returns {string} 处理后的HTML字符串
+ */
+export function removeBackgroundStyle(html) {
+ if (!html) return "";
+
+ // 1. 处理图片:设置宽度为100%屏幕宽度
+ let processedHtml = html.replace(
+ /
]*)src=["']([^"']*)["']([^>]*)>/gi,
+ '
',
+ );
+
+ // 2. 移除所有元素的背景色样式
+ processedHtml = processedHtml.replace(/background-color:[^;"]*;?/gi, "");
+
+ // 3. 移除可能冲突的宽度/高度属性
+ processedHtml = processedHtml
+ .replace(/width=["'][^"']*["']/gi, "")
+ .replace(/height=["'][^"']*["']/gi, "");
+
+ return processedHtml;
+}