You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allows you to export the content from Facebook’s Draft.js editor to an abstract syntax tree (AST). Together with the companion draft-js-ast-importer it forms the full cycle of exporting content from a Draft.js editor instance and then re-importing it.
Why?
Draft.js supports exporting its content JSON, but this format is a little awkward. Blocks of text are disconnected from their style and entity ranges, and the depth of blocks isn’t implicit. So when it comes to rendering that content in contexts outside a Draft.js editor, you need to have an understanding of how those ranges should be applied and how blocks fit together.
The AST generated by draft-js-ast-exporter mitigates this issue by joining common ranges together into marked inline or entity sections, and by allowing blocks to be nested within one another based on their depth.
You can modify the entity data as it’s being exported by passing in an options.entityModifiers object with a functions to modify that entity-type’s data:
importexporterfrom'draft-js-ast-exporter'constoptions={entityModifiers: {'LINK': (data)=>{letcopy=Object.assign({},data)// Strip protocols from `url` keyscopy.url=copy.url.replace(/^https?:/,'')returncopy}},}constast=exporter(editorState,options)