Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
paste: function (editor, editPath) {
this._editPath = editPath;
//网页粘贴检查
const html = clipboard.readHtml();
if (html && html.length > 2) {
//形如 <div><img src="..."></div> 格式的 html 视为图片粘贴
const htmlMatch = html.match(/^(<div>)?\s*<img src="(.*?)">\s*(<\/div>)?$/i);
if (htmlMatch && htmlMatch.length >= 4) {
// file 协议视为本地图片,转移图片
if (htmlMatch[2].indexOf('file:') === 0) {
this._pasteImg('file', htmlMatch[2], function (state, text, title) {
if (state) {
text = '![](' + text + title + ')' + ' \n';
editor.insertText(text, editor);
}
}, editor);
}
// http 协议视为远程图片
else if (htmlMatch[2].indexOf('http') === 0) {
//如果此时粘贴板能读取图片,则读取</div>