tijiao
This commit is contained in:
@@ -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', // 按钮文本
|
||||
|
||||
Reference in New Issue
Block a user