From 6b3da6e4167ecc63762712e359dbcffdd11e4b59 Mon Sep 17 00:00:00 2001 From: Cory Forsyth Date: Tue, 19 Jan 2016 14:42:51 -0500 Subject: [PATCH] Pass parser plugins to HTMLParser from editor#loadPost fixes #296 --- src/js/editor/editor.js | 3 ++- tests/unit/editor/editor-test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/js/editor/editor.js b/src/js/editor/editor.js index cb5401f50..496e4dde8 100644 --- a/src/js/editor/editor.js +++ b/src/js/editor/editor.js @@ -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); diff --git a/tests/unit/editor/editor-test.js b/tests/unit/editor/editor-test.js index c0c530544..4633b0f9e 100644 --- a/tests/unit/editor/editor-test.js +++ b/tests/unit/editor/editor-test.js @@ -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 = '

'; + let editor = new Editor({html, parserPlugins: [parserPlugin]}); + assert.ok(!!editor.post, 'editor loads post'); + + assert.deepEqual(seenTagNames, ['TEXTAREA', 'IMG']); +});