Draft-js保存和显示HTML [英] Draft-js saving and displaying HTML

查看:496
本文介绍了Draft-js保存和显示HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人想出任何教程/演习来使用Draft-js来简单地保存编辑器状态并将其显示为html.我一直在搜索和尝试,但仍然无法显示html.似乎大多数人只是保存编辑器状态并将其重新加载到编辑器中,而不是将其显示为html.

I'm wondering if anyone came up with any tutorial / walk through for Draft-js to simply save editor state and display it as html to the user. I've been searching and trying and still unable to display html. It seems like most are just saving the editor state and reloading it into the editor instead of displaying it as html.

似乎大多数与convertFromRaw和convertToRaw一起使用,但是其中包含的步骤数量似乎应该简化很多步骤,并在此处提供示例:

It seems like most go with convertFromRaw and convertToRaw, but the amount of steps included in that seems like there are quite a few steps that should be simplified, and the example here: https://draftjs.org/docs/api-reference-data-conversion.html#content seems like it's only used to place the content back in the editor later.

也许我什至没有在寻找合适的工具-我只希望编辑器保存格式化的文本并显示它.我不确定为什么这么难找到资源,或者我只是找错了位置(似乎有太多的Draft-js软件包没有太多的文档和示例IMO).但是,我相信这一定不难实现.

Maybe I'm not even looking at the right tool - I simply want an editor to save formatted text and display it. I'm not sure why the resources are so hard to find, or if I'm just looking in the wrong spots (seems like there are too many packages for Draft-js with not much documentation and examples IMO). However, I'm sure this must not be hard to accomplish.

推荐答案

Draftjs专注于在编辑器中显示富文本.但是,如果要显示相应的HTML,则必须使用一个名为draftjs-export-html的外部程序包. import {stateToHTML} from 'draft-js-export-html';

Draftjs is concentrating on displaying rich text within an editor. However, if you want to display the corresponding HTML you have to use an external package called draftjs-export-html. import {stateToHTML} from 'draft-js-export-html';

您可以使用let html = stateToHTML(editorState.getCurrentContent(), options);获取html,这将执行粗体,斜体等样式的基本格式设置.您还可以使用option参数传递您自己的draftjs entities的样式首选项.

you can get the html using let html = stateToHTML(editorState.getCurrentContent(), options); this will do the basic formatting of styles like bold, italic etc. You can also pass your own styling preferences of your draftjs entites using the option parameter.

https://www.npmjs.com/package/draft-js -export-html

这篇关于Draft-js保存和显示HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆