psy*_*21d 5 javascript prose-mirror tiptap
该代码可以工作,但绝对没有效果(节点未创建)
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',
},
},
Run Code Online (Sandbox Code Playgroud)
这段代码会抛出一个错误
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)
},
}
},
})
...
Run Code Online (Sandbox Code Playgroud)
<button @click="editor.chain().focus().togglePage().run()" :class="{ 'is-active': editor.isActive('PageNode') }">
toggle page
</button>
Run Code Online (Sandbox Code Playgroud)
也许我丢失了重要参数?
我以检查 TableCell 节点为例,工作正常,但我未能在代码中执行相同的功能
| 归档时间: |
|
| 查看次数: |
4108 次 |
| 最近记录: |