Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Draft.js conversion without browser

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
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

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();

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!