1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-11 17:53:59 +02:00

add ability to not normalize on state creation

This commit is contained in:
Ian Storm Taylor
2017-03-05 16:54:26 -08:00
parent cc26e6c60a
commit eb4854006a
3 changed files with 32 additions and 5 deletions

View File

@@ -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 })
}
/**

View File

@@ -182,7 +182,7 @@ const Raw = {
selection = Raw.deserializeSelection(object.selection, options)
}
return State.create({ document, selection })
return State.create({ document, selection }, options)
},
/**

View File

@@ -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()', () => {