微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在tiptap编辑器中强制第一个节点进入H1?

如何解决如何在tiptap编辑器中强制第一个节点进入H1?

我正在构建一个简单的富文本编辑器来编写博客。我想强制第一个节点始终是用户不能删除标题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>
  `,})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。