Prosemirror: A way for node types to control/restrict their content

Created on 25 Feb 2016  路  6Comments  路  Source: ProseMirror/prosemirror

We will need this for various use cases:

  • 'heading can only appear as the first node of a section'
  • 'a figure has a caption followed by one or more images'
  • 'all rows in a table have the same number of columns'

Designing a usable and sound way to do this remains a partially open question. Feel free to submit additional use cases. This also ties into #187 since preserving these restrictions during replace is the hardest aspect.

Most helpful comment

This has landed in ba983894ed6e...f6839de36f2b. Please open new issues for problems.

All 6 comments

Few use cases of mine:

  • Lists can only contain paragraphs and other lists
  • Blockquotes can only contain paragraphs
  • Headings can only contain text and certain marks (notably NOT bold)

@wes-r Those can all be expressed in the current system (and the new one will definitely keep on supporting them)

I have the following use case: Creating a "task list" which contains list items that have exactly two children, a checkbox as the first child and a paragraph as the second. Apart from this constraint the task list should behave the same way as a BulletList and ListItems (support nesting, lifting, sinking).

This sounds as a sanitizer/validator.
Which could be expressed by parsing the (markup-) tree using, for example, an EBNF grammar.

Note that during editing the tree doesn't necessarily match the grammar. For example, in the above task-list description, the insertion of both child-nodes is probably not an atomic operation. This makes it necessary to either insert missing nodes, or have specific validation moments.

The idea is to enforce these at every point. Inserting two child nodes can be made an atomic operation. There are some other constraints, such as paragraphs not being empty, that would be better suited for a validator, since it'd be painful to not be able to have empty paragraphs during editing.

This has landed in ba983894ed6e...f6839de36f2b. Please open new issues for problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marijnh picture marijnh  路  6Comments

theefer picture theefer  路  6Comments

SamyPesse picture SamyPesse  路  3Comments

bradleyayers picture bradleyayers  路  4Comments

lastnigtic picture lastnigtic  路  6Comments