Created
April 6, 2024 04:57
-
-
Save keymastervn/685a0657d591fd4c85a044987139f42f to your computer and use it in GitHub Desktop.
[slate-html-serializer] Slate 0.47 html->slate deserializer playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/ianstormtaylor/slate/blob/a0b7976cb9a2812d8d96361e9993fe8853a2cc64/packages/slate-html-serializer/src/index.js | |
const jsdom = require("jsdom") | |
const { JSDOM } = jsdom | |
// global.DOMParser = new JSDOM().window.DOMParser | |
const Html = require('slate-html-serializer').default; | |
var input = ` | |
<body> | |
<p> | |
<p>The Slate editor gives you <em>complete</em> control over the logic you can add.</p> | |
<p>In its simplest form, when representing plain text, Slate is a glorified <code>«textarea»</code>. But you can augment it to be much more than that.</p> | |
<p>Check out <a href="http://slatejs.org">http://slatejs.org</a> for examples!</p> | |
</p> | |
</body> | |
` | |
// const parser = new Html({ parseHtml: JSDOM.fragment, rules: RULES }); | |
const parser = new Html({ parseHtml: JSDOM.fragment}); | |
// parser.parseHtml(input); | |
const util = require('util'); | |
console.log( | |
JSON.stringify( | |
parser.deserialize(input, {toJSON: true}), | |
null, indent = 2 | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "tmp_playground", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"jsdom": "^24.0.0", | |
"slate": "0.47.9", | |
"slate-html-serializer": "0.8.11" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment