Skip to content

Instantly share code, notes, and snippets.

View jankurianski's full-sized avatar

Jan Kurianski jankurianski

View GitHub Profile
@bengotow
bengotow / deserialize.js
Created January 8, 2018 18:49
Slate HTML deserialize with nested block / inline handling
const DefaultParse = HtmlSerializer.parseHtml;
HtmlSerializer.parseHtml = html => {
const tree = DefaultParse.apply(HtmlSerializer, [html]);
const collapse = require('collapse-whitespace');
collapse(tree);
// ensure that no DIVs contain both element children and text node children. This is
// not allowed by Slate's core schema: blocks must contain inlines and text OR blocks.
// https://docs.slatejs.org/guides/data-model#documents-and-nodes
const treeWalker = document.createTreeWalker(tree, NodeFilter.SHOW_ELEMENT, {