npm install sraft-convert --save
or yarn add sraft-convert
Extensibly serialize Draft.js ContentState
to HTML.
基本用法:
const html = convertToHTML(editorState.getCurrentContent());
高级用法:
const html = convertToHTML(editorState.getCurrentContent(), {
entityTransform: (entity, text) => {
// 根据类型做不同的处理
if (entity.type === "block-xxx") {
return `<a href="${entity.data.url}">${text}</a>`;
}
// 返回空则按默认处理
return "";
},
});