Skip to content

Commit

Permalink
Pass parser plugins to HTMLParser from editor#loadPost
Browse files Browse the repository at this point in the history
fixes #296
  • Loading branch information
bantic committed Jan 19, 2016
1 parent 2fff20a commit 6b3da6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class Editor {
return mobiledocParsers.parse(this.builder, this.mobiledoc);
} else if (this.html) {
if (typeof this.html === 'string') {
return new HTMLParser(this.builder).parse(this.html);
let options = {plugins: this._parserPlugins};
return new HTMLParser(this.builder, options).parse(this.html);
} else {
let dom = this.html;
return this._parser.parse(dom);
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/editor/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,15 @@ test('#destroy does not clear selection if it is outside the editor element', (a

assert.equal(window.getSelection().rangeCount, 1, 'selection is not cleared');
});

test('editor parses HTML post using parser plugins', (assert) => {
let seenTagNames = [];
let parserPlugin = function(element) {
seenTagNames.push(element.tagName);
};
let html = '<p><textarea></textarea><img></p>';
let editor = new Editor({html, parserPlugins: [parserPlugin]});
assert.ok(!!editor.post, 'editor loads post');

assert.deepEqual(seenTagNames, ['TEXTAREA', 'IMG']);
});

0 comments on commit 6b3da6e

Please sign in to comment.