问题描述
我正在构建一个简单的富文本编辑器来编写博客。我想强制第一个节点始终是用户不能删除的标题(h1
标签)!
有没有办法做到这一点?
解决方法
您可以在初始化时将其放入内容中:
const editor = useEditor({
extensions: [
StarterKit.configure({
heading: {
levels: [1,2],},}),Dropcursor.configure({
color: "#4B5563",Placeholder.configure({
showOnlyWhenEditable: true,placeholder: "Write something or press Enter to add a new block",CodeBlockLowlight.configure({
lowlight,TaskList,CustomTaskItem,ListItem,Blockquote,CustomOrderedList,CustomHorizontalRule,Table.configure({
resizable: true,TableRow,TableHeader,TableCell,],editorProps: {
attributes: {
class: "focus:outline-none subpixel-antialiased",autofocus: true,// THIS
content: `
<h1>Hello there </h1>
`,})