diff --git a/src/models/state.js b/src/models/state.js index 4243f10dc..384219590 100644 --- a/src/models/state.js +++ b/src/models/state.js @@ -42,10 +42,12 @@ class State extends new Record(DEFAULTS) { * Create a new `State` with `properties`. * * @param {Object|State} properties + * @param {Object} options + * @property {Boolean} normalize * @return {State} */ - static create(properties = {}) { + static create(properties = {}, options = {}) { if (properties instanceof State) return properties const document = Document.create(properties.document) @@ -58,9 +60,9 @@ class State extends new Record(DEFAULTS) { const state = new State({ document, selection }) - return state.transform() - .normalize(SCHEMA) - .apply({ save: false }) + return options.normalize === false + ? state + : state.transform().normalize(SCHEMA).apply({ save: false }) } /** diff --git a/src/serializers/raw.js b/src/serializers/raw.js index b4327e32b..0e59e9d33 100644 --- a/src/serializers/raw.js +++ b/src/serializers/raw.js @@ -182,7 +182,7 @@ const Raw = { selection = Raw.deserializeSelection(object.selection, options) } - return State.create({ document, selection }) + return State.create({ document, selection }, options) }, /** diff --git a/test/serializers/index.js b/test/serializers/index.js index bc9e59599..7af9f4806 100644 --- a/test/serializers/index.js +++ b/test/serializers/index.js @@ -54,6 +54,31 @@ describe('serializers', () => { } }) }) + + it('optionally does not normalize', () => { + const html = new Html(require('./fixtures/html/deserialize/inline-with-is-void').default) + const input = fs.readFileSync(resolve(__dirname, './fixtures/html/deserialize/inline-with-is-void/input.html'), 'utf8') + const serialized = html.deserialize(input, { toRaw: true, normalize: false }) + assert.deepEqual(serialized, { + kind: 'state', + document: { + kind: 'document', + nodes: [ + { + kind: 'block', + type: 'paragraph', + nodes: [ + { + kind: 'inline', + type: 'link', + isVoid: true, + } + ] + } + ] + } + }) + }) }) describe('serialize()', () => {