提交
This commit is contained in:
@@ -22,7 +22,7 @@ export default {
|
||||
var txt = document.createElement('textarea');
|
||||
txt.innerHTML = html;
|
||||
return txt.value;
|
||||
},
|
||||
},
|
||||
//去掉最外层自定义的span标签
|
||||
extractContentWithoutOuterSpan(cell) {
|
||||
var str = ''
|
||||
@@ -52,12 +52,12 @@ export default {
|
||||
const regex = /\[(\d+(?:–\d+)?(?:, ?\d+(?:–\d+)?)*)\]/g;
|
||||
|
||||
str = str.replace(/<blue>/g, '').replace(/<\/blue>/g, ''); // 先去掉所有的 <blue> 标签
|
||||
|
||||
|
||||
if (regex.test(str)) {
|
||||
str = str.replace(regex, function(match) {
|
||||
str = str.replace(regex, function (match) {
|
||||
// 提取出方括号中的内容,并进行匹配
|
||||
const content = match.slice(1, match.length - 1); // 去掉方括号
|
||||
|
||||
|
||||
// 判断是否符合条件,纯数字、逗号后有空格、连字符
|
||||
if (/^\d+$/.test(content) || /, ?/.test(content) || /–/.test(content)) {
|
||||
return `<blue>${match}</blue>`; // 如果符合条件则加上蓝色标签
|
||||
@@ -65,8 +65,8 @@ export default {
|
||||
return match; // 如果不符合条件,则保持原样
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 如果没有 <span> 标签,直接返回原始 HTML 内容
|
||||
@@ -295,18 +295,18 @@ export default {
|
||||
formattedText = capitalizeFirstLetter(formattedText);
|
||||
|
||||
// 添加蓝色标签
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const regex = /\[(\d+(?:–\d+)?(?:, ?\d+(?:–\d+)?)*)\]/g;
|
||||
|
||||
formattedText = formattedText.replace(/<blue>/g, '').replace(/<\/blue>/g, ''); // 先去掉所有的 <blue> 标签
|
||||
|
||||
|
||||
if (regex.test(formattedText)) {
|
||||
formattedText = formattedText.replace(regex, function(match) {
|
||||
formattedText = formattedText.replace(regex, function (match) {
|
||||
// 提取出方括号中的内容,并进行匹配
|
||||
const content = match.slice(1, match.length - 1); // 去掉方括号
|
||||
|
||||
|
||||
// 判断是否符合条件,纯数字、逗号后有空格、连字符
|
||||
if (/^\d+$/.test(content) || /, ?/.test(content) || /–/.test(content)) {
|
||||
return `<blue>${match}</blue>`; // 如果符合条件则加上蓝色标签
|
||||
@@ -315,10 +315,10 @@ export default {
|
||||
});
|
||||
}
|
||||
console.log("After replacement:", formattedText); // 调试:查看替换后的文本
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
paragraphText += formattedText;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ export default {
|
||||
}
|
||||
},
|
||||
transformHtmlString(inputHtml) {
|
||||
|
||||
|
||||
inputHtml = inputHtml.replace(/(<[^>]+) style="[^"]*"/g, '$1'); // 移除style属性
|
||||
inputHtml = inputHtml.replace(/(<[^>]+) class="[^"]*"/g, '$1'); // 移除class属性
|
||||
|
||||
@@ -386,6 +386,41 @@ export default {
|
||||
|
||||
},
|
||||
|
||||
cleanAndParseWordContent(content) {
|
||||
// 1️⃣ 解析成 <p> 段落数组
|
||||
let tempDiv = document.createElement('div');
|
||||
tempDiv.innerHTML = content; // 解析 HTML 内容
|
||||
let paragraphs = tempDiv.querySelectorAll("p"); // 选取所有 <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️⃣ 如果最终内容为空,则替换为 `""`
|
||||
return text.trim() === "" ? "" : text;
|
||||
});
|
||||
|
||||
console.log(parsedData); // 输出数组,方便调试
|
||||
return parsedData;
|
||||
}
|
||||
|
||||
|
||||
,
|
||||
|
||||
|
||||
parseTableToArray(tableString, callback) {
|
||||
@@ -1240,7 +1275,7 @@ export default {
|
||||
}
|
||||
});
|
||||
ed.ui.registry.addButton('addRow', {
|
||||
icon:'duplicate-row',
|
||||
icon: 'duplicate-row',
|
||||
text: 'Add Row', // 下拉框标题
|
||||
onAction: function () {
|
||||
var edSelection = ed.selection;
|
||||
@@ -1257,7 +1292,7 @@ export default {
|
||||
vueInstance.$emit('onAddRow', dataId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
// 添加自定义菜单项
|
||||
ed.ui.registry.addButton('Save', {
|
||||
@@ -1300,7 +1335,7 @@ export default {
|
||||
emTags[i].parentNode.replaceChild(iTag, emTags[i]);
|
||||
}
|
||||
content = div.innerHTML;
|
||||
|
||||
|
||||
vueInstance.$emit('saveContent', content, dataId);
|
||||
}
|
||||
}
|
||||
@@ -1390,8 +1425,8 @@ export default {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
ed.ui.registry.addButton('commentAdd', {
|
||||
icon: 'comment-add',
|
||||
text: 'Comment Add',
|
||||
@@ -1519,7 +1554,7 @@ export default {
|
||||
ed.setContent('');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
ed.ui.registry.addButton('customBlue', {
|
||||
text: 'Blue', // 按钮文本
|
||||
@@ -1537,80 +1572,80 @@ export default {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ed.ui.registry.addButton('myuppercase', {
|
||||
text: 'A', // 按钮文本
|
||||
|
||||
|
||||
onAction: function () {
|
||||
// 在选中的文本周围包裹 <blue> 标签
|
||||
var selectedText = ed.selection.getContent({ format: 'html' });
|
||||
|
||||
// 确保选中的文本是单个单词,包括空格
|
||||
if (selectedText.trim() && /^[\s\w]+$/.test(selectedText)) {
|
||||
// 使用正则将选中的文本中的第一个字母大写
|
||||
var capitalizedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function(match, p1, p2) {
|
||||
return p1 + p2.toUpperCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(capitalizedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
|
||||
}
|
||||
// 使用正则将选中的文本中的第一个字母大写
|
||||
var capitalizedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function (match, p1, p2) {
|
||||
return p1 + p2.toUpperCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(capitalizedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
ed.ui.registry.addButton('myuppercase', {
|
||||
text: 'A', // 按钮文本
|
||||
|
||||
|
||||
onAction: function () {
|
||||
// 在选中的文本周围包裹 <blue> 标签
|
||||
var selectedText = ed.selection.getContent({ format: 'html' });
|
||||
|
||||
// 确保选中的文本是单个单词,包括空格
|
||||
if (selectedText.trim() && /^[\s\w]+$/.test(selectedText)) {
|
||||
// 使用正则将选中的文本中的第一个字母大写
|
||||
var capitalizedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function(match, p1, p2) {
|
||||
return p1 + p2.toUpperCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(capitalizedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
|
||||
}
|
||||
// 使用正则将选中的文本中的第一个字母大写
|
||||
var capitalizedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function (match, p1, p2) {
|
||||
return p1 + p2.toUpperCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(capitalizedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
ed.ui.registry.addButton('myuppercasea', {
|
||||
text: 'a', // 按钮文本(小写字母)
|
||||
onAction: function () {
|
||||
// 获取选中的文本,保留 HTML 格式
|
||||
var selectedText = ed.selection.getContent({ format: 'html' });
|
||||
// 获取选中的文本,保留 HTML 格式
|
||||
var selectedText = ed.selection.getContent({ format: 'html' });
|
||||
|
||||
// 确保选中的文本是单个有效的单词,包括空格
|
||||
if (selectedText.trim() && /^[\s\w]+$/.test(selectedText)) {
|
||||
// 使用正则将选中的文本中的第一个字母转换为小写
|
||||
var lowercasedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function(match, p1, p2) {
|
||||
return p1 + p2.toLowerCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(lowercasedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
}
|
||||
// 确保选中的文本是单个有效的单词,包括空格
|
||||
if (selectedText.trim() && /^[\s\w]+$/.test(selectedText)) {
|
||||
// 使用正则将选中的文本中的第一个字母转换为小写
|
||||
var lowercasedText = selectedText.replace(/(^|\s)([a-zA-Z])/g, function (match, p1, p2) {
|
||||
return p1 + p2.toLowerCase();
|
||||
});
|
||||
|
||||
// 替换选中的文本,保持空格和其他内容
|
||||
ed.selection.setContent(lowercasedText);
|
||||
} else {
|
||||
vueInstance.$message.error(vueInstance.$t('commonTable.selectWord'));
|
||||
}
|
||||
}
|
||||
});
|
||||
ed.ui.registry.addButton('Line', {
|
||||
text: '−', // 按钮文本
|
||||
onAction: function () {
|
||||
// 插入 `−` 符号到当前光标位置
|
||||
ed.insertContent('−');
|
||||
}
|
||||
});
|
||||
});
|
||||
ed.ui.registry.addButton('Line', {
|
||||
text: '−', // 按钮文本
|
||||
onAction: function () {
|
||||
// 插入 `−` 符号到当前光标位置
|
||||
ed.insertContent('−');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
ed.ui.registry.addButton('removeBlue', {
|
||||
text: 'Blue', // 按钮文本
|
||||
onAction: function () {
|
||||
@@ -1660,7 +1695,7 @@ export default {
|
||||
{ selector: '.tox-tbtn[data-mce-name="customblue"]', className: 'tinymce-custom-button-blue' },
|
||||
{ selector: '.tox-tbtn[data-mce-name="removeblue"]', className: 'tinymce-custom-button-removeblue' }
|
||||
];
|
||||
|
||||
|
||||
// 遍历每个按钮并为每个按钮添加类
|
||||
buttons.forEach(item => {
|
||||
const buttonElements = document.querySelectorAll(item.selector);
|
||||
@@ -1672,7 +1707,7 @@ export default {
|
||||
});
|
||||
}, 100); // 延迟执行,确保按钮渲染完成
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 通用递归方法
|
||||
|
||||
|
||||
Reference in New Issue
Block a user