如何在draft.js中添加自定义按钮以链接

时间:2019-04-30 08:05:47

标签: reactjs draftjs html-editor draft-js-plugins

我正在这样的“管理”面板中使用draft.js

enter image description here

现在,我需要为具有自定义href的代码添加自定义按钮,如下所示:

 link = `RCAApp://PATH/${ANYKEY}`

我的代码是这样的:

 _toggleBlockType(blockType) {
const { visible } = this.state
const { editorState } = this.props;
const selection = editorState.getSelection();
const start = selection.getStartOffset();
const end = selection.getEndOffset();

if (blockType === 'LINK' && (end !== start)) {
  this.setState({
    visible: !visible,
  });
}
else if (blockType === 'LINK' && (end === start)) {
  notification.error({
    message: `Error`,
    description: `You need to select a word!`,
  });
}
this.onChange(
  RichUtils.toggleBlockType(
    editorState,
    blockType
  )
 );
}

现在我不知道如何将自定义的href注入html文本本身,该文档还不足以理解。

0 个答案:

没有答案