Skip to content

Commit 8a1ac8c

Browse files
committed
🎨 Improve Microsoft Excel Compatibility
1 parent 89e9b5f commit 8a1ac8c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/src/protyle/util/compatibility.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export const encodeBase64 = (text: string): string => {
2424
};
2525

2626
export const getTextSiyuanFromTextHTML = (html: string) => {
27+
const trimmedHtml = html.trimStart();
28+
if (trimmedHtml.startsWith("<html")) {
29+
const htmlTagEnd = trimmedHtml.indexOf(">");
30+
if (htmlTagEnd > 0) {
31+
const htmlTag = trimmedHtml.substring(0, htmlTagEnd);
32+
// 兼容 Microsoft Excel 应用,HTML 以包含 Excel 命名空间声明的 html 元素开头(备注:从 WPS 复制也有这个命名空间)
33+
if (htmlTag.includes('xmlns:x="urn:schemas-microsoft-com:office:excel"')) {
34+
// 粘贴表格不需要解析 textSiyuan https://ld246.com/article/1763027417781/comment/1763032527460#comments
35+
return {
36+
textSiyuan: "",
37+
textHtml: html.replace(/<!--data-siyuan='[^']+'-->/g, "")
38+
};
39+
}
40+
}
41+
}
2742
const siyuanMatch = html.match(/<!--data-siyuan='([^']+)'-->/);
2843
let textSiyuan = "";
2944
let textHtml = html;
@@ -38,7 +53,7 @@ export const getTextSiyuanFromTextHTML = (html: string) => {
3853
textSiyuan = decoder.decode(bytes);
3954
}
4055
// 移除注释节点,保持原有的 text/html 内容
41-
textHtml = html.replace(/<!--data-siyuan='[^']+'-->/, "");
56+
textHtml = html.replace(/<!--data-siyuan='[^']+'-->/g, "");
4257
} catch (e) {
4358
console.log("Failed to decode siyuan data from HTML comment:", e);
4459
}

0 commit comments

Comments
 (0)