diff --git a/core/editor.js b/core/editor.js index b55c002c38..0a0f212c28 100644 --- a/core/editor.js +++ b/core/editor.js @@ -7,6 +7,8 @@ import { LeafBlot } from 'parchment'; import CursorBlot from '../blots/cursor'; import Block, { bubbleFormats } from '../blots/block'; import Break from '../blots/break'; +import ScrollBlot from '../blots/scroll'; +import TextBlot from '../blots/text'; const ASCII = /^[ -~]*$/; @@ -131,6 +133,10 @@ class Editor { return extend.apply(extend, formatsArr); } + getHTML(index, length) { + return convertHTML(this.scroll, index, length); + } + getText(index, length) { return this.getContents(index, length) .filter(op => typeof op.insert === 'string') @@ -214,6 +220,71 @@ class Editor { } } +function convertListHTML(items, lastIndent) { + if (items.length === 0) { + if (lastIndent <= 0) { + return ''; + } + return `${convertListHTML([], lastIndent - 1)}`; + } + const [{ child, offset, length, indent }, ...rest] = items; + if (indent > lastIndent) { + return `
${html}`; + } } class CodeBlock extends Block { diff --git a/formats/formula.js b/formats/formula.js index 99731fb162..4ebd2cbfbe 100644 --- a/formats/formula.js +++ b/formats/formula.js @@ -19,6 +19,11 @@ class Formula extends Embed { static value(domNode) { return domNode.getAttribute('data-value'); } + + html() { + const { formula } = this.value(); + return `${formula}`; + } } Formula.blotName = 'formula'; Formula.className = 'ql-formula'; diff --git a/formats/video.js b/formats/video.js index 332e2d5dd1..6af30cd000 100644 --- a/formats/video.js +++ b/formats/video.js @@ -40,6 +40,11 @@ class Video extends BlockEmbed { super.format(name, value); } } + + html() { + const { video } = this.value(); + return `${video}`; + } } Video.blotName = 'video'; Video.className = 'ql-video'; diff --git a/modules/clipboard.js b/modules/clipboard.js index ea9eef1a73..b8e030ab11 100644 --- a/modules/clipboard.js +++ b/modules/clipboard.js @@ -126,8 +126,8 @@ class Clipboard extends Module { onCaptureCopy(e) { if (e.defaultPrevented) return; this.quill.update(); - const [range, native] = this.quill.selection.getRange(); - this.onCopy(e, range, native); + const [range] = this.quill.selection.getRange(); + this.onCopy(e, range); e.preventDefault(); } @@ -143,17 +143,11 @@ class Clipboard extends Module { e.preventDefault(); } - onCopy(e, range, nativeRange) { + onCopy(e, range) { const text = this.quill.getText(range); - const fragment = nativeRange.native.cloneContents(); - Array.from(fragment.querySelectorAll('select')).forEach(select => { - select.parentNode.removeChild(select); - }); - const div = this.quill.root.ownerDocument.createElement('div'); - div.style.whiteSpace = 'pre-wrap'; - div.appendChild(fragment); + const html = this.quill.getSemanticHTML(range); e.clipboardData.setData('text/plain', text); - e.clipboardData.setData('text/html', div.outerHTML); + e.clipboardData.setData('text/html', html); } onPaste(e, range) {