diff --git a/docs/walkthroughs/saving-and-loading-html-content.md b/docs/walkthroughs/saving-and-loading-html-content.md index fa167acb0..34baadeed 100644 --- a/docs/walkthroughs/saving-and-loading-html-content.md +++ b/docs/walkthroughs/saving-and-loading-html-content.md @@ -103,27 +103,29 @@ const rules = [ // Switch deserialize to handle more blocks... deserialize(el, next) { const type = BLOCK_TAGS[el.tagName.toLowerCase()] - if (!type) return - return { - object: 'block', - type: type, - nodes: next(el.childNodes), + if (type) { + return { + object: 'block', + type: type, + nodes: next(el.childNodes), + } } }, // Switch serialize to handle more blocks... serialize(obj, children) { - if (obj.object != 'block') return - switch (obj.type) { - case 'paragraph': - return

{children}

- case 'quote': - return
{children}
- case 'code': - return ( -
-              {children}
-            
- ) + if (obj.object == 'block') { + switch (obj.type) { + case 'paragraph': + return

{children}

+ case 'quote': + return
{children}
+ case 'code': + return ( +
+                {children}
+              
+ ) + } } }, }, @@ -154,26 +156,28 @@ const rules = [ { deserialize(el, next) { const type = BLOCK_TAGS[el.tagName.toLowerCase()] - if (!type) return - return { - object: 'block', - type: type, - nodes: next(el.childNodes), + if (type) { + return { + object: 'block', + type: type, + nodes: next(el.childNodes), + } } }, serialize(obj, children) { - if (obj.object != 'block') return - switch (obj.type) { - case 'code': - return ( -
-              {children}
-            
- ) - case 'paragraph': - return

{children}

- case 'quote': - return
{children}
+ if (obj.object == 'block') { + switch (obj.type) { + case 'code': + return ( +
+                {children}
+              
+ ) + case 'paragraph': + return

{children}

+ case 'quote': + return
{children}
+ } } }, }, @@ -181,22 +185,24 @@ const rules = [ { deserialize(el, next) { const type = MARK_TAGS[el.tagName.toLowerCase()] - if (!type) return - return { - object: 'mark', - type: type, - nodes: next(el.childNodes), + if (type) { + return { + object: 'mark', + type: type, + nodes: next(el.childNodes), + } } }, serialize(obj, children) { - if (obj.object != 'mark') return - switch (obj.type) { - case 'bold': - return {children} - case 'italic': - return {children} - case 'underline': - return {children} + if (obj.object == 'mark') { + switch (obj.type) { + case 'bold': + return {children} + case 'italic': + return {children} + case 'underline': + return {children} + } } }, }, diff --git a/examples/paste-html/index.js b/examples/paste-html/index.js index bf20ddd96..6d45807e0 100644 --- a/examples/paste-html/index.js +++ b/examples/paste-html/index.js @@ -50,68 +50,73 @@ const RULES = [ { deserialize(el, next) { const block = BLOCK_TAGS[el.tagName.toLowerCase()] - if (!block) return - return { - object: 'block', - type: block, - nodes: next(el.childNodes), + if (block) { + return { + object: 'block', + type: block, + nodes: next(el.childNodes), + } } }, }, { deserialize(el, next) { const mark = MARK_TAGS[el.tagName.toLowerCase()] - if (!mark) return - return { - object: 'mark', - type: mark, - nodes: next(el.childNodes), + if (mark) { + return { + object: 'mark', + type: mark, + nodes: next(el.childNodes), + } } }, }, { // Special case for code blocks, which need to grab the nested childNodes. deserialize(el, next) { - if (el.tagName.toLowerCase() != 'pre') return - const code = el.childNodes[0] - const childNodes = - code && code.tagName.toLowerCase() == 'code' - ? code.childNodes - : el.childNodes + if (el.tagName.toLowerCase() == 'pre') { + const code = el.childNodes[0] + const childNodes = + code && code.tagName.toLowerCase() == 'code' + ? code.childNodes + : el.childNodes - return { - object: 'block', - type: 'code', - nodes: next(childNodes), + return { + object: 'block', + type: 'code', + nodes: next(childNodes), + } } }, }, { // Special case for images, to grab their src. deserialize(el, next) { - if (el.tagName.toLowerCase() != 'img') return - return { - object: 'block', - type: 'image', - isVoid: true, - nodes: next(el.childNodes), - data: { - src: el.getAttribute('src'), - }, + if (el.tagName.toLowerCase() == 'img') { + return { + object: 'block', + type: 'image', + isVoid: true, + nodes: next(el.childNodes), + data: { + src: el.getAttribute('src'), + }, + } } }, }, { // Special case for links, to grab their href. deserialize(el, next) { - if (el.tagName.toLowerCase() != 'a') return - return { - object: 'inline', - type: 'link', - nodes: next(el.childNodes), - data: { - href: el.getAttribute('href'), - }, + if (el.tagName.toLowerCase() == 'a') { + return { + object: 'inline', + type: 'link', + nodes: next(el.childNodes), + data: { + href: el.getAttribute('href'), + }, + } } }, },