|
@@ -171,12 +171,10 @@ export default {
|
|
|
branding: false, // 品牌
|
|
branding: false, // 品牌
|
|
|
statusbar: false, // 状态栏
|
|
statusbar: false, // 状态栏
|
|
|
entity_encoding: 'raw', // raw不编码任何字符;named: 使用命名实体(如 );numeric: 使用数字实体(如  )
|
|
entity_encoding: 'raw', // raw不编码任何字符;named: 使用命名实体(如 );numeric: 使用数字实体(如  )
|
|
|
-
|
|
|
|
|
setup: (editor) => {
|
|
setup: (editor) => {
|
|
|
- var that = this;
|
|
|
|
|
- editor.on('GetContent', function (e) {
|
|
|
|
|
|
|
+ editor.on('GetContent', (e) => {
|
|
|
if (e.format === 'html') {
|
|
if (e.format === 'html') {
|
|
|
- e.content = that.smartPreserveLineBreaks(editor, e.content);
|
|
|
|
|
|
|
+ e.content = this.smartPreserveLineBreaks(editor, e.content);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -242,7 +240,7 @@ export default {
|
|
|
if (e.keyCode === 8 || e.keyCode === 46) {
|
|
if (e.keyCode === 8 || e.keyCode === 46) {
|
|
|
// 延迟执行以确保删除已完成
|
|
// 延迟执行以确保删除已完成
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- that.cleanupRemovedAnnotations(editor);
|
|
|
|
|
|
|
+ this.cleanupRemovedAnnotations(editor);
|
|
|
}, 500);
|
|
}, 500);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -250,7 +248,7 @@ export default {
|
|
|
// 也可以监听剪切操作
|
|
// 也可以监听剪切操作
|
|
|
editor.on('Cut', () => {
|
|
editor.on('Cut', () => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- that.cleanupRemovedAnnotations(editor);
|
|
|
|
|
|
|
+ this.cleanupRemovedAnnotations(editor);
|
|
|
}, 500);
|
|
}, 500);
|
|
|
});
|
|
});
|
|
|
// editor.on('NodeChange', function (e) {
|
|
// editor.on('NodeChange', function (e) {
|
|
@@ -262,7 +260,7 @@ export default {
|
|
|
// ) {
|
|
// ) {
|
|
|
// const annotationId = e.element.getAttribute('data-annotation-id');
|
|
// const annotationId = e.element.getAttribute('data-annotation-id');
|
|
|
// e.element.parentNode.removeChild(e.element);
|
|
// e.element.parentNode.removeChild(e.element);
|
|
|
- // that.$emit('selectContentSetMemo', null, annotationId);
|
|
|
|
|
|
|
+ // this.$emit('selectContentSetMemo', null, annotationId);
|
|
|
// }
|
|
// }
|
|
|
// });
|
|
// });
|
|
|
},
|
|
},
|
|
@@ -285,11 +283,13 @@ export default {
|
|
|
file_picker_callback: this.filePickerCallback,
|
|
file_picker_callback: this.filePickerCallback,
|
|
|
init_instance_callback: this.isFill || this.isViewNote ? this.initInstanceCallback : '',
|
|
init_instance_callback: this.isFill || this.isViewNote ? this.initInstanceCallback : '',
|
|
|
paste_enable_default_filters: false, // 禁用默认的粘贴过滤器
|
|
paste_enable_default_filters: false, // 禁用默认的粘贴过滤器
|
|
|
|
|
+ paste_as_text: true, // 默认作为纯文本粘贴
|
|
|
// 粘贴预处理
|
|
// 粘贴预处理
|
|
|
paste_preprocess(plugin, args) {
|
|
paste_preprocess(plugin, args) {
|
|
|
let content = args.content;
|
|
let content = args.content;
|
|
|
// 使用正则表达式去掉 style 中的 background 属性
|
|
// 使用正则表达式去掉 style 中的 background 属性
|
|
|
content = content.replace(/background(-color)?:[^;]+;/g, '');
|
|
content = content.replace(/background(-color)?:[^;]+;/g, '');
|
|
|
|
|
+ content = content.replace(/\t/g, ' '); // 将制表符替换为4个空格
|
|
|
args.content = content;
|
|
args.content = content;
|
|
|
},
|
|
},
|
|
|
// 指定在 WebKit 中粘贴时要保留的样式
|
|
// 指定在 WebKit 中粘贴时要保留的样式
|
|
@@ -377,20 +377,19 @@ export default {
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
smartPreserveLineBreaks(editor, content) {
|
|
smartPreserveLineBreaks(editor, content) {
|
|
|
- var that = this;
|
|
|
|
|
- var body = editor.getBody();
|
|
|
|
|
- var originalParagraphs = Array.from(body.getElementsByTagName('p'));
|
|
|
|
|
|
|
+ let body = editor.getBody();
|
|
|
|
|
+ let originalParagraphs = Array.from(body.getElementsByTagName('p'));
|
|
|
|
|
|
|
|
- var tempDiv = document.createElement('div');
|
|
|
|
|
|
|
+ let tempDiv = document.createElement('div');
|
|
|
tempDiv.innerHTML = content;
|
|
tempDiv.innerHTML = content;
|
|
|
- var outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
|
|
|
|
|
|
|
+ let outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
|
|
|
|
|
|
|
|
- outputParagraphs.forEach(function (outputP, index) {
|
|
|
|
|
- var originalP = originalParagraphs[index];
|
|
|
|
|
|
|
+ outputParagraphs.forEach((outputP, index) => {
|
|
|
|
|
+ let originalP = originalParagraphs[index];
|
|
|
|
|
|
|
|
if (originalP && outputP.innerHTML === '') {
|
|
if (originalP && outputP.innerHTML === '') {
|
|
|
// 判断这个空段落是否应该包含 <br>
|
|
// 判断这个空段落是否应该包含 <br>
|
|
|
- var shouldHaveBr = that.shouldPreserveLineBreak(originalP, index, originalParagraphs);
|
|
|
|
|
|
|
+ let shouldHaveBr = this.shouldPreserveLineBreak(originalP, index, originalParagraphs);
|
|
|
if (shouldHaveBr) {
|
|
if (shouldHaveBr) {
|
|
|
outputP.innerHTML = '<br>';
|
|
outputP.innerHTML = '<br>';
|
|
|
}
|
|
}
|
|
@@ -408,8 +407,8 @@ export default {
|
|
|
|
|
|
|
|
// 规则2:如果段落位于内容中间(不是第一个或最后一个)
|
|
// 规则2:如果段落位于内容中间(不是第一个或最后一个)
|
|
|
if (index > 0 && index < allParagraphs.length - 1) {
|
|
if (index > 0 && index < allParagraphs.length - 1) {
|
|
|
- var prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
|
|
|
|
|
- var nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
|
|
|
|
|
|
|
+ let prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
|
|
|
|
|
+ let nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
|
|
|
|
|
|
|
|
if (prevHasContent && nextHasContent) {
|
|
if (prevHasContent && nextHasContent) {
|
|
|
return true;
|
|
return true;
|
|
@@ -417,7 +416,7 @@ export default {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 规则3:如果段落是通过回车创建的(前后有内容)
|
|
// 规则3:如果段落是通过回车创建的(前后有内容)
|
|
|
- var isBetweenContent = false;
|
|
|
|
|
|
|
+ let isBetweenContent = false;
|
|
|
if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
|
|
if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
|
|
|
isBetweenContent = true;
|
|
isBetweenContent = true;
|
|
|
}
|
|
}
|
|
@@ -721,7 +720,7 @@ export default {
|
|
|
let isHasPinyin = content
|
|
let isHasPinyin = content
|
|
|
.split(/<[^>]+>/g)
|
|
.split(/<[^>]+>/g)
|
|
|
.filter((item) => item)
|
|
.filter((item) => item)
|
|
|
- .some((item) => item.match(/[a-zA-Z]+\d(\s| )*/));
|
|
|
|
|
|
|
+ .some((item) => item.match(/[a-zA-Z]+\d+(\s| )+/));
|
|
|
|
|
|
|
|
if (!isHasPinyin) {
|
|
if (!isHasPinyin) {
|
|
|
return;
|
|
return;
|
|
@@ -887,7 +886,6 @@ export default {
|
|
|
},
|
|
},
|
|
|
// 删除span里面的文字之后,会出现空 span 标签残留,需处理掉
|
|
// 删除span里面的文字之后,会出现空 span 标签残留,需处理掉
|
|
|
handleEmptySpan(editor) {
|
|
handleEmptySpan(editor) {
|
|
|
- let that = this;
|
|
|
|
|
const selection = editor.selection;
|
|
const selection = editor.selection;
|
|
|
const selectedNode = selection.getNode();
|
|
const selectedNode = selection.getNode();
|
|
|
// 如果选中的是注释span内的内容
|
|
// 如果选中的是注释span内的内容
|
|
@@ -902,7 +900,7 @@ export default {
|
|
|
span.parentNode.replaceChild(document.createTextNode(''), span);
|
|
span.parentNode.replaceChild(document.createTextNode(''), span);
|
|
|
|
|
|
|
|
// 从存储中移除注释
|
|
// 从存储中移除注释
|
|
|
- that.$emit('selectContentSetMemo', null, annotationId);
|
|
|
|
|
|
|
+ this.$emit('selectContentSetMemo', null, annotationId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|