1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 12:41:44 +02:00

Some fixes (#1225)

Ensure el has a tagName (e.g. textnode will not have a tagName) - found in slack channel

Strict equality checks for strings
This commit is contained in:
David O'Trakoun
2017-10-13 13:07:12 -04:00
committed by Ian Storm Taylor
parent a68a6466f9
commit 13025d79a6

View File

@@ -27,7 +27,7 @@ const String = new Record({
const TEXT_RULE = { const TEXT_RULE = {
deserialize(el) { deserialize(el) {
if (el.tagName.toLowerCase() == 'br') { if (el.tagName && el.tagName.toLowerCase() === 'br') {
return { return {
kind: 'text', kind: 'text',
ranges: [{ text: '\n' }], ranges: [{ text: '\n' }],
@@ -45,7 +45,7 @@ const TEXT_RULE = {
}, },
serialize(obj, children) { serialize(obj, children) {
if (obj.kind == 'string') { if (obj.kind === 'string') {
return children return children
.split('\n') .split('\n')
.reduce((array, text, i) => { .reduce((array, text, i) => {
@@ -66,7 +66,7 @@ const TEXT_RULE = {
*/ */
function defaultParseHtml(html) { function defaultParseHtml(html) {
if (typeof DOMParser == 'undefined') { if (typeof DOMParser === 'undefined') {
throw new Error('The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.') throw new Error('The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.')
} }
@@ -341,7 +341,7 @@ class Html {
*/ */
serializeNode = (node) => { serializeNode = (node) => {
if (node.kind == 'text') { if (node.kind === 'text') {
const ranges = node.getRanges() const ranges = node.getRanges()
return ranges.map(this.serializeRange) return ranges.map(this.serializeRange)
} }
@@ -405,7 +405,7 @@ class Html {
*/ */
cruftNewline = (element) => { cruftNewline = (element) => {
return !(element.nodeName == '#text' && element.value == '\n') return !(element.nodeName === '#text' && element.value == '\n')
} }
} }