|
|
@@ -171,18 +171,13 @@ export default {
|
|
|
branding: false, // 品牌
|
|
|
statusbar: false, // 状态栏
|
|
|
entity_encoding: 'raw', // raw不编码任何字符;named: 使用命名实体(如 );numeric: 使用数字实体(如  )
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
setup: (editor) => {
|
|
|
-
|
|
|
- var that=this
|
|
|
- editor.on('GetContent', function(e) {
|
|
|
- if (e.format === 'html') {
|
|
|
- e.content = that.smartPreserveLineBreaks(editor, e.content);
|
|
|
- }
|
|
|
+ editor.on('GetContent', (e) => {
|
|
|
+ if (e.format === 'html') {
|
|
|
+ e.content = this.smartPreserveLineBreaks(editor, e.content);
|
|
|
+ }
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
let isRendered = false; // 标记是否已渲染
|
|
|
editor.on('init', () => {
|
|
|
editor.getBody().style.fontSize = this.init.font_size; // 设置默认字体大小
|
|
|
@@ -245,7 +240,7 @@ export default {
|
|
|
if (e.keyCode === 8 || e.keyCode === 46) {
|
|
|
// 延迟执行以确保删除已完成
|
|
|
setTimeout(() => {
|
|
|
- that.cleanupRemovedAnnotations(editor);
|
|
|
+ this.cleanupRemovedAnnotations(editor);
|
|
|
}, 500);
|
|
|
}
|
|
|
});
|
|
|
@@ -253,7 +248,7 @@ export default {
|
|
|
// 也可以监听剪切操作
|
|
|
editor.on('Cut', () => {
|
|
|
setTimeout(() => {
|
|
|
- that.cleanupRemovedAnnotations(editor);
|
|
|
+ this.cleanupRemovedAnnotations(editor);
|
|
|
}, 500);
|
|
|
});
|
|
|
// editor.on('NodeChange', function (e) {
|
|
|
@@ -265,7 +260,7 @@ export default {
|
|
|
// ) {
|
|
|
// const annotationId = e.element.getAttribute('data-annotation-id');
|
|
|
// e.element.parentNode.removeChild(e.element);
|
|
|
- // that.$emit('selectContentSetMemo', null, annotationId);
|
|
|
+ // this.$emit('selectContentSetMemo', null, annotationId);
|
|
|
// }
|
|
|
// });
|
|
|
},
|
|
|
@@ -288,6 +283,7 @@ export default {
|
|
|
file_picker_callback: this.filePickerCallback,
|
|
|
init_instance_callback: this.isFill || this.isViewNote ? this.initInstanceCallback : '',
|
|
|
paste_enable_default_filters: false, // 禁用默认的粘贴过滤器
|
|
|
+ paste_as_text: true, // 默认作为纯文本粘贴
|
|
|
// 粘贴预处理
|
|
|
paste_preprocess(plugin, args) {
|
|
|
let content = args.content;
|
|
|
@@ -379,59 +375,56 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ smartPreserveLineBreaks(editor, content) {
|
|
|
+ let body = editor.getBody();
|
|
|
+ let originalParagraphs = Array.from(body.getElementsByTagName('p'));
|
|
|
+
|
|
|
+ let tempDiv = document.createElement('div');
|
|
|
+ tempDiv.innerHTML = content;
|
|
|
+ let outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
|
|
|
|
|
|
- smartPreserveLineBreaks(editor, content) {
|
|
|
- var that=this
|
|
|
- var body = editor.getBody();
|
|
|
- var originalParagraphs = Array.from(body.getElementsByTagName('p'));
|
|
|
-
|
|
|
- var tempDiv = document.createElement('div');
|
|
|
- tempDiv.innerHTML = content;
|
|
|
- var outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
|
|
|
-
|
|
|
- outputParagraphs.forEach(function(outputP, index) {
|
|
|
- var originalP = originalParagraphs[index];
|
|
|
-
|
|
|
- if (originalP && outputP.innerHTML === '') {
|
|
|
- // 判断这个空段落是否应该包含 <br>
|
|
|
- var shouldHaveBr =that.shouldPreserveLineBreak(originalP, index, originalParagraphs);
|
|
|
- if (shouldHaveBr) {
|
|
|
- outputP.innerHTML = '<br>';
|
|
|
+ outputParagraphs.forEach((outputP, index) => {
|
|
|
+ let originalP = originalParagraphs[index];
|
|
|
+
|
|
|
+ if (originalP && outputP.innerHTML === '') {
|
|
|
+ // 判断这个空段落是否应该包含 <br>
|
|
|
+ let shouldHaveBr = this.shouldPreserveLineBreak(originalP, index, originalParagraphs);
|
|
|
+ if (shouldHaveBr) {
|
|
|
+ outputP.innerHTML = '<br>';
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return tempDiv.innerHTML;
|
|
|
- },
|
|
|
-
|
|
|
- shouldPreserveLineBreak(paragraph, index, allParagraphs) {
|
|
|
- // 规则1:如果段落原本包含 <br>
|
|
|
- if (paragraph.innerHTML.includes('<br>')) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 规则2:如果段落位于内容中间(不是第一个或最后一个)
|
|
|
- if (index > 0 && index < allParagraphs.length - 1) {
|
|
|
- var prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
|
|
|
- var nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
|
|
|
-
|
|
|
- if (prevHasContent && nextHasContent) {
|
|
|
+ });
|
|
|
+
|
|
|
+ return tempDiv.innerHTML;
|
|
|
+ },
|
|
|
+
|
|
|
+ shouldPreserveLineBreak(paragraph, index, allParagraphs) {
|
|
|
+ // 规则1:如果段落原本包含 <br>
|
|
|
+ if (paragraph.innerHTML.includes('<br>')) {
|
|
|
return true;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 规则3:如果段落是通过回车创建的(前后有内容)
|
|
|
- var isBetweenContent = false;
|
|
|
- if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
|
|
|
- isBetweenContent = true;
|
|
|
- }
|
|
|
- if (index < allParagraphs.length - 1 && allParagraphs[index + 1].textContent.trim() !== '') {
|
|
|
- isBetweenContent = true;
|
|
|
- }
|
|
|
-
|
|
|
- return isBetweenContent;
|
|
|
- },
|
|
|
|
|
|
+ // 规则2:如果段落位于内容中间(不是第一个或最后一个)
|
|
|
+ if (index > 0 && index < allParagraphs.length - 1) {
|
|
|
+ let prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
|
|
|
+ let nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
|
|
|
+
|
|
|
+ if (prevHasContent && nextHasContent) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 规则3:如果段落是通过回车创建的(前后有内容)
|
|
|
+ let isBetweenContent = false;
|
|
|
+ if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
|
|
|
+ isBetweenContent = true;
|
|
|
+ }
|
|
|
+ if (index < allParagraphs.length - 1 && allParagraphs[index + 1].textContent.trim() !== '') {
|
|
|
+ isBetweenContent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isBetweenContent;
|
|
|
+ },
|
|
|
|
|
|
// 设置背景色
|
|
|
setBackgroundColor() {
|
|
|
@@ -726,7 +719,7 @@ export default {
|
|
|
let isHasPinyin = content
|
|
|
.split(/<[^>]+>/g)
|
|
|
.filter((item) => item)
|
|
|
- .some((item) => item.match(/[a-zA-Z]+\d(\s| )*/));
|
|
|
+ .some((item) => item.match(/[a-zA-Z]+\d+(\s| )+/));
|
|
|
|
|
|
if (!isHasPinyin) {
|
|
|
return;
|