Is it possible to call `convertFromHTML` on NodeJS?
See original GitHub issueDo you want to request a feature or report a bug?
I want to migrate from my legacy html content in DB to Draft Raw Object.
var raw = converrtToRaw(ContentState.createFromBlockArray(convertFromHTML('<div></div>)))
What is the current behavior?
convertFromHTML requires document
object.
ReferenceError: document is not defined
at getSafeBodyFromHTML (/PROJECT_DIRECTORY/node_modules/draft-js/lib/getSafeBodyFromHTML.js:27:19)
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.
Run the below codes in Node
const djs = require('draft-js')
console.log(djs.convertFromHTML('<div></div>'))
What is the expected behavior?
return {blocks: [...], ....}
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
Node v4.4.4
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Nextjs with Draft js - document is not defined when i initiate ...
It errors when I initialize the editorState with a content. const blocksFromHTML = convertFromHTML( "<p>Hey this <strong>editor</strong> rocks ...
Read more >Data Conversion | Draft.js
This is useful when saving an editor state for storage, conversion to other formats, or other usage within an application. convertFromHTML() #.
Read more >bytescout - npm
For Node.js. Install it via: npm install bytescout --save. Local development.
Read more >Convert from HTML to Image - Pdfcrowd
Hi! I need to convert from HTML to image. Is there a way to do it with you tool? If not, which tool...
Read more >TechTip: Hapi to Authenticate You | Programming - Other
Here we see the Node.js iToolkit being used to call a *PGM object, ... use of tools like html2jade.org to convert from HTML...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was just playing around with a similar implementation.
Rather than executing within a synthetic dom, you can use the DOMBuilder input to the
convertFromHTML
, which is just an alias forconvertFromHTMLtoContentBlocks
and has this signature:You can instantiate a simple DOMBuilder using
jsdom
like so:Then pass this to
convertFromHTML
as an argument:Note: You still need to attach the variables
HTMLElement
andHTMLAnchorElement
to global because they are used for type checking withinconvertFromHTMLtoContentBlocks
.Cool! There is probably no better way, though you could create a separate VM context to load jsdom and Draft into if you don’t want to pollute your main one. I don’t see us making changes to support this better since convertFromHTML is designed around a browser implementation so I’m going to close this out.