This commit is contained in:
2025-03-18 11:19:25 +08:00
parent 43279b6a99
commit aa69846e09
5 changed files with 122 additions and 37 deletions

View File

@@ -360,10 +360,11 @@ export default {
const breaks = paragraph.getElementsByTagName("w:br");
for (const br of breaks) {
paragraphText += "<br>";
paragraphText += "<br/>";
}
cellText += paragraphText;
console.log('cellText at line 366:', cellText)
}
rowArray.push({
@@ -644,33 +645,39 @@ export default {
let tempDiv = document.createElement('div');
tempDiv.innerHTML = content; // 解析 HTML 内容
let paragraphs = tempDiv.querySelectorAll("p"); // 选取所有 <p> 作为数据项
// 2⃣ 将 <p> 内容转换为数组,处理空标签对
// 2⃣ 将 <p> 内容转换为数组,处理内容
let parsedData = Array.from(paragraphs).map(p => {
let text = p.innerHTML.trim(); // 获取内容,去除两端空格
// 3⃣ 移除 <o:p>Word 复制的无效标签)
text = text.replace(/<\/?o:p>/g, "");
// 4移除 style="..."(防止 Word 带入无用样式)
text = text.replace(/\s*style="[^"]*"/g, "");
// 5替换 <strong> 为 <b>
text = text.replace(/<strong>/g, "<b>").replace(/<\/strong>/g, "</b>");
// 6⃣ 替换 <em> 为 <i>
text = text.replace(/<em>/g, "<i>").replace(/<\/em>/g, "</i>");
// 7⃣ 处理空标签对:<i> </i>、<b> </b>、<span> </span> 等
text = text.replace(/<[^>]+>\s*<\/[^>]+>/g, "");
// 8️⃣ 如果最终内容为空,则替换为 `""`
// 3**正确移除 <o:p>Word 复制的无效标签)**
text = text.replace(/<\/?o:p[^>]*>/g, "");
// 4**移除所有 style="..."**
text = text.replace(/\s*style="[^"]*"/gi, "");
// 5**修正标签替换**
text = text.replace(/<strong>/gi, "<b>").replace(/<\/strong>/gi, "</b>");
text = text.replace(/<em>/gi, "<i>").replace(/<\/em>/gi, "</i>");
// 6⃣ **移除空的 span、b、i 标签**
text = text.replace(/<span>\s*<\/span>/gi, "");
text = text.replace(/<b>\s*<\/b>/gi, "");
text = text.replace(/<i>\s*<\/i>/gi, "");
// 7️⃣ **确保不移除半个标签(修复匹配规则)**
text = text.replace(/<[^\/>]+>\s*<\/[^>]+>/gi, match => {
return match.trim() === "" ? "" : match;
});
// 8⃣ **返回最终内容**
return text.trim() === "" ? "" : text;
});
console.log(parsedData); // 输出数组,方便调试
return parsedData;
}
,
@@ -1825,6 +1832,22 @@ export default {
}
}
});
ed.ui.registry.addButton('LateX', {
text: 'LateX', // 按钮文本
className: 'custom-button-blue', // 添加自定义类
// shortcut: "Ctrl+J",
onAction: function () {
// 在选中的文本周围包裹 <blue> 标签
// var selectedText = ed.selection.getContent();
// console.log('selectedText at line 529:', selectedText);
// if (selectedText) {
// var wrappedText = `<blue>${selectedText}</blue>`;
// ed.selection.setContent(wrappedText);
// } else {
// this.$message.error('请选择要添加蓝色的文本');
// }
}
});
ed.ui.registry.addButton('myuppercase', {
text: 'A', // 按钮文本