Skip to content

Commit

Permalink
rename pasteHTML to make clear risks
Browse files Browse the repository at this point in the history
following React's dangerouslySetInnerHTML example closes #981
  • Loading branch information
jhchen committed Sep 18, 2016
1 parent d28916a commit d1149ad
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class Quill {
this.clipboard = this.theme.addModule('clipboard');
this.history = this.theme.addModule('history');
this.theme.init();
this.pasteHTML(`<div class='ql-editor' style="white-space: normal;">${html}<p><br></p></div>`);
let contents = this.clipboard.convert(`<div class='ql-editor' style="white-space: normal;">${html}<p><br></p></div>`);
this.setContents(contents);
this.history.clear();
if (options.readOnly) {
this.disable();
Expand Down Expand Up @@ -100,6 +101,15 @@ class Quill {
this.selection.setRange(null);
}

dangerouslyPasteHTML(index, html, source = Emitter.sources.API) {
if (typeof index === 'string') {
return this.setContents(this.clipboard.convert(index), html);
} else {
let paste = this.clipboard.convert(html);
return this.updateContents(new Delta().retain(index).concat(paste), source);
}
}

deleteText(index, length, source) {
[index, length, , source] = overload(index, length, source);
let range = this.getSelection();
Expand Down Expand Up @@ -234,13 +244,8 @@ class Quill {
return this.emitter.once.apply(this.emitter, arguments);
}

pasteHTML(index, html, source = Emitter.sources.API) {
if (typeof index === 'string') {
return this.setContents(this.clipboard.convert(index), html);
} else {
let paste = this.clipboard.convert(html);
return this.updateContents(new Delta().retain(index).concat(paste), source);
}
pasteHTML(index, html, source) {
this.dangerouslyPasteHTML(index, html, source);
}

removeFormat(index, length, source) {
Expand Down

0 comments on commit d1149ad

Please sign in to comment.