How to create nested nodes by commands/input-rules

For some reason, I have to wrap heading Node in, say section Node. The NodeSpec is something like:

heading: {
     // copied from prosemirror-schema-basic, but `group: 'block' is removed
},
section: {
     content: 'heading',
     attrs: {
         ...
     }
     ...
} 

Now I hope everything still works as the basic demo:

  1. clicking the menu button to turn the current stuff into a heading
  2. # triggers a new heading

But I found it awkward. I tried to wrapIn the current line in a section node first, and then setBlockType the attrs for the section node. But it does not work, since the section node can only contains heading.

You’ll probably have to create ReplaceAroundStep instances to do this cleanly—replacing the old block’s opening token with section and heading open tokens, and its close token with heading and section close tokens. Getting the offsets right requires some careful token counting.

Nice to know it.