Advice for Restricted Editing

I’m using ProseMirror to build a Markdown editor with support for

  • Creating named regions in a Markdown file and
  • Embedding a named region from in a different file
  • When is open, any edits to the embedded region should be saved to instead

My current solution for the embedded editor works like this:

  • The embedded document is loaded in a NodeView which uses a nested ProseMirror instance
  • The NodeView loads the entire “embedded” document, creates an EditorState for it, and searches for the user-specified named region
  • The NodeView creates a separate EditorState object, and passes it to the nested ProseMirror editor
  • The dispatchTransaction() for the nested editor uses to apply changes made by the nested editor to the entire embedded document, so it can be properly saved

The problem is that it’s a bit inconvenient to have essentially two copies of the region’s state, since we need to keep them in sync. My questions are:

  • Is there an easier way to restrict an EditorView to show only a slice / fragment / single node of a document?
  • If not, does my approach sound reasonable, or might there be an easier way to accomplish the same thing?

Possible alternative solutions:

  1. Set display:none on all nodes outside of the restricted region, and use filterTransaction to make sure no edits change the frozen region


You can set doc to any node, when creating a state. The editor will only show that node.

I should also be possible to simply make the imported doc part of the wrapping doc (given that you set up the schema to allow this), and then sync up your representation of the inner document when the outer document changes.

1 Like

If I understood correctly: You want to display both Markdown files at the same time and keep the named region in sync?

If you don’t need to keep the ProseMirror steps (or just StepMaps) history of the embedded document (for undo/redo history or for PM’s collab editing solution), maybe you could just define a “region” node and move the children node tree between documents. Or you could also use PM JSON or even Markdown as you exchange format?