此代码更改具有匹配文本的块的类型。
如何在Slate.js
中添加此块之后的另一个块?
import {Range} from 'slate';
import {blockTypes} from 'core/slate-types';
export default function autoreplaceHeading(node, matched, change) {
const matchedLength = matched[0].length;
return change
.setBlocks(blockTypes.HEADING)
.deleteAtRange(
Range.create({
anchorKey: node.key,
focusKey: node.key,
anchorOffset: matched.index,
focusOffset: matched.index + matchedLength
})
);
}