1

此代码有效但绝对无效(未创建节点)

const PageNode = Node.create({
  name: 'PageNode',
  // content: 'block+',
  content: 'inline*',
  marks: '_',
  
  inline: true,
  group: "inline",
  draggable: true,

  code: true,
  isolating: true,
  defining: true,
  // draggable: true
  defaultOptions: {
    HTMLAttributes: {
      class: 'page pagebreak',
    },
  },

此代码引发错误

const PageNode = Node.create({
  name: 'PageNode',
  // content: 'block+',
  content: 'block+',
  marks: '_',
  
  inline: false,
  group: "block",
  draggable: true,

  code: true,
  isolating: true,
  defining: true,
  // draggable: true
  defaultOptions: {
    HTMLAttributes: {
      class: 'page pagebreak',
    },
  },
  addAttributes() {
    // Return an object with attribute configuration
    return {
      class: {
        default: 'page pagebreak',
      },
    }
  },
  parseHTML() {
    return [
      {
        tag: 'div',
        preserveWhitespace: 'full',
      },
    ]
  },
  renderHTML({ HTMLAttributes }) {
    return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
  },
  addCommands() {
    return {
      setPage: attributes => ({ commands }) => {
        return commands.setNode('PageNode', attributes)
      },
      togglePage: attributes => ({ commands }) => {
        return commands.toggleNode('PageNode', 'PageNode', attributes)
      },
    }
  },
})
...

需要放置节点时出错

<button @click="editor.chain().focus().togglePage().run()" :class="{ 'is-active': editor.isActive('PageNode') }"> 切换页面

也许我丢失了重要参数?

我以检查 TableCell 节点为例,工作正常,但我未能在我的代码中执行相同的功能

4

0 回答 0