Disallow nested lists

Hello,

I want to disallow nested lists like:

  • List item
  • Sub item

or:

  1. List item
  • sub item

in the editor. I found this ticket: Prevent nested Lists · Issue #31 · ProseMirror/prosemirror · GitHub but I could not get it working. Both OrderedList and BulletList use NodeKind.list_item. So my idea was to allow only Text or Paragraph nodes in NodeKind.list_item.

But contains() in ListItem:

  export class ListItem extends Block {
    get kind() { return NodeKind.list_item }
    get contains() { return NodeKind.text }
  }

returned an error:

RangeError: Wrap not possible

Any ideas? Thx a lot

It might be easier to make list items contain only paragraphs (though that will also require giving paragraph a new, specific kind). To make list items contain text you’ll have to make them textblocks (i.e. you’ll need a new class that inherits from Textblock).

I would definitely prefer to use paragraphs.

So I have to:

  1. Giving the Paragraph-class a new kind ? Currently it has NodeKind.block
  2. Setting List Item class to contains only Paragraph-class

?

Can you may give a rough example plz?

I think you should be ok if you

  • Define a variable paragraphKind which is new NodeKind("paragraph", [NodeKind.block]).

  • Use a subclass of the default Paragraph which has a get kind() { return paragraphKind } getter.

  • Use a subclass of the default ListItem with has a get contains() { return paragraphKind } getter.

(I realize this is awful, and am working on a more usable and powerful system for this stuff right now, which will hopefully make it into 0.7.0.)

Thx marijn. I’m looking forward o see 0.7.0 :slight_smile: