I'm in the middle of migrating some saved editor text/data from another rich text editor (Quill) to using Draft.js. The data exist in files in a format digestible by the current text editor, and I would like to transform these files to Draft.js format.
All of the rich text editors have some sort of data-to-html and html-to-data conversion functions, which come in handy here.
My plan was to convert the current editor text/data to html using a converter of the current editor, and then convert the resulting html to the format supported by Draft.js using some converter from the Draft.js package.
However, it seems (I could be wrong) that all of the Draft.js converters require the browser in some form or another, so I'm unable to this as a backend/server-side application only. Is there a tool that I'm missing and/or is there another type of solution to this?
TL;DR:
editor_data --(phase 1)--> html --(phase 2)--> Draft.js_data
phase 2 seems to require browser, I would like to not involve browser
convert data from quill to markdown and then convert markdown back to draftjs accepted format, below code is an example of export and can be executed using node, follow the same logic for import
quill --> markdown --> draftjs
https://github.com/sstur/draft-js-utils
const {
convertFromRaw
} = require('draft-js');
const {stateToMarkdown} = require('draft-js-export-markdown');
const {draftToMarkdown} = require('markdown-draft-js');
const converter = () => {
const sampleMarkup =
{"blocks":[{"key":"dsf1t","text":"👍👎🏾 this isn't trueeeeeeeeeeeeeeeee","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":0},{"offset":1,"length":2,"key":1}],"data":{}}],"entityMap":{"0":{"type":"emoji","mutability":"IMMUTABLE","data":{"emojiUnicode":"👍"}},"1":{"type":"emoji","mutability":"IMMUTABLE","data":{"emojiUnicode":"👎🏾"}}}} ;
const blocksFromHTML = convertFromRaw(sampleMarkup);
// const state = ContentState.createFromBlockArray(blocksFromHTML);
console.log('state: ', stateToMarkdown(blocksFromHTML));
console.log('state: ', draftToMarkdown(sampleMarkup));
}
converter();