How to use the clipboard.readHtml function in clipboard

To help you get started, we’ve selected a few clipboard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TevinLi / amWiki / lib / richPaste.js View on Github external
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*(&lt;\/div&gt;)?$/i);
            if (htmlMatch &amp;&amp; htmlMatch.length &gt;= 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>