From 4b0ddacfbe672c9f8a4ed60f14121874401b4bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 24 Sep 2019 11:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96neditor=E7=9A=84HTML=E7=B2=98?= =?UTF-8?q?=E8=B4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/neditor/index.wc | 46 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/neditor/index.wc b/src/neditor/index.wc index 7323d19..611e1a6 100644 --- a/src/neditor/index.wc +++ b/src/neditor/index.wc @@ -39,6 +39,26 @@ border-radius: 4px; } +table { + border-spacing: 0; + border-collapse: collapse; + + tr { + background: #fff; + } + thead tr { + background: nth($cp, 1); + } + th, + td { + padding: 6px 12px; + border: 1px solid nth($cp, 3); + } + th { + font-weight: bold; + } +} + .neditor { position: relative; flex: 1; @@ -268,7 +288,13 @@ export default class Neditor { } get value() { - return this.__EDITOR__.innerHTML + var html = this.__EDITOR__.innerHTML + if (~html.indexOf('')) { + html = + '' + + html + } + return html } set value(val) { @@ -461,9 +487,27 @@ export default class Neditor { this.__pasteFn = bind(this.__EDITOR__, 'paste', ev => { ev.preventDefault() + var html = ev.clipboardData.getData('text/html') var txt = ev.clipboardData.getData('text/plain') var items = ev.clipboardData.items + if (html) { + html = html + .replace(/\t/g, ' ') + .replace(/]*>/, '') + .replace( + /]*? href\s?=\s?["']?([^"']*)["']?[^>]*?>/g, + '' + ) + .replace( + /]*? href\s?=\s?["']?([^"']*)["']?[^>]*?>/g, + '' + ) + .replace(/<(?!a|img)([\w\-]+)[^>]*>/g, '<$1>') + + return this.exec('insertHtml', html) + } + if (txt) { return this.exec('insertText', txt) }