Skip to content

Commit

Permalink
fix: 粘贴企业微信内容时编辑器有报错 #336
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Oct 30, 2022
1 parent 6d7aa7a commit d333504
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ export default class Editor {
if (!html || !this.options.convertWhenPaste) {
return true;
}
/**
* 这里需要处理一个特殊逻辑:
* 从excel中复制而来的内容,剪切板里会有一张图片(一个<img>元素)和一段纯文本,在这种场景下,需要丢掉图片,直接粘贴纯文本
* 与此同时,当剪切板里有图片和其他html标签时(从web页面上复制的内容),则需要走下面的html转md的逻辑
* 基于上述两个场景,才有了下面四行奇葩的代码
*/
const test = html.replace(/<(html|head|body|!)/g, '');
if (test.match(/<[a-zA-Z]/g).length <= 1 && /<img/.test(test)) {
if (test.match(/<[a-zA-Z]/g)?.length <= 1 && /<img/.test(test)) {
return true;
}
let divObj = document.createElement('DIV');
Expand Down

0 comments on commit d333504

Please sign in to comment.