# How do I define a Schema NodeSpec requiring a set number of elements within?

**URL:** https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132
**Category:** Uncategorized
**Created:** [January 10, 2018, 11:30pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132 "2018-01-10T23:30:40Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![chaseme](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/chaseme/32/512_2.png) [@chaseme](https://discuss.prosemirror.net/u/chaseme)
#### Post date: [January 10, 2018, 11:30pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/1 "2018-01-10T23:30:40Z")

</div>

I’m still trying to wrap my head around the way Prosemirror is structured. Sorry if I’m going about this in completely the wrong manner.

I would like ProseMirror to recognize the structure that we have in our documents. They are currently represented as just two separate paragraph tags enclosed within a div with a special attribute and class.

In my HTML, I have a DOM structure like so:

```auto
<div data-label="property-label" class="orgProperty">
    <p>:Name:</p><p>Item 1</p>
</div>

```

In my schema definition, I defined the NodeSpec? like so:

```auto
org_property: {
      defining: true,
      priority: 60,
      content: "paragraph{2}",
      parseDOM: [{tag: 'div.orgProperty[data-label="property-label"]'}],
      toDOM() { return ["div", {"data-label": "property-label", "class": "orgProperty"}, 0] }
    }

```

Currently, when prosemirror parses this structure, it will turn the HTML it into the following:

```auto
<p>:Name:</p>
<p>Item</p>

```

It basically just strips out the enclosing div. I’m using the [ProseMirror dino example](https://prosemirror.net/examples/dino/) as a starting point… My thought was that I needed to create a NodeSpec defining the enclosing div. The div will always have two paragraph tags within. Is there anything obvious that I’m doing incorrectly?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [January 11, 2018, 7:58am UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/2 "2018-01-11T07:58:03Z")

</div>

The code you pasted looks good, but it seems the parser isn’t matching that node type for some reason. Did you confirm that the schema you are using is the right one, and has that node type in it?

---

<div class="post-metadata">

### Author: ![chaseme](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/chaseme/32/512_2.png) [@chaseme](https://discuss.prosemirror.net/u/chaseme)
#### Post date: [January 11, 2018, 4:27pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/3 "2018-01-11T16:27:29Z")

</div>

Here is a screenshot of the schema object right before the dino example creates the `EditorView()` instance.

 ![Screenshot_2018-01-11_10-23-33](https://discuss.prosemirror.net/uploads/secondsite/original/1X/0e5889c1801c581beddaea3fd413917fcdb26a81.png)

I see `org_property` is in the listing of nodes. Is there something special that I need to check on the `org_property` NodeType?

The constant `dinoSchema` is used directly after my `console.log(dinoSchema)` line to create and assign `window.view`, so I’m pretty sure the `EditorView()` is using the same schema with the correct NodeType.

---

<div class="post-metadata">

### Author: ![chaseme](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/chaseme/32/512_2.png) [@chaseme](https://discuss.prosemirror.net/u/chaseme)
#### Post date: [January 11, 2018, 7:10pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/4 "2018-01-11T19:10:54Z")

</div>

If it helps, here is a full code example of this issue I am facing:

> **[Glitch](https://glitch.com/edit/#!/platinum-cough)**
>
> Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [January 11, 2018, 8:39pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/5 "2018-01-11T20:39:01Z")

</div>

You failed to specify a way in which the `org_property` node can actually be part of the document—it doesn’t appear in any content expression, and it’s not part of any group that does appear in content expressions.

---

<div class="post-metadata">

### Author: ![chaseme](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/chaseme/32/512_2.png) [@chaseme](https://discuss.prosemirror.net/u/chaseme)
#### Post date: [January 11, 2018, 9:13pm UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/6 "2018-01-11T21:13:27Z")

</div>

Interesting… So just because I added a node to the schema doesn’t mean that it’s allowed within the document?

So it order for a `org_property` to appear, it must be in a content expression under another node in the schema or assigned a group which must also be used in another content expression?

Would it be correct to modify the `doc` node’s content expression to match a `org_property` node?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [January 12, 2018, 7:09am UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/7 "2018-01-12T07:09:00Z")

</div>

> [@chaseme](#):
>
> Would it be correct to modify the doc node’s content expression to match a org\_property node?

Yes, if the top level is the only place you want this to appear, doing something like `"(block | org_property)+"` in `doc` would work.

---

<div class="post-metadata">

### Author: ![jiewuza](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jiewuza/32/1113_2.png) [@jiewuza](https://discuss.prosemirror.net/u/jiewuza)
#### Post date: [July 7, 2019, 2:40am UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/8 "2019-07-07T02:40:44Z")

</div>

I just encountered the same issue.

I tried the schema

```auto
new Schema({
  nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block")
    .append({org_property: {
      defining: true,
      priority: 60,
      content: "paragraph{2}",
      parseDOM: [{tag: 'div.orgProperty[data-label="property-label"]'}],
      toDOM() { return ["div", {"data-label": "property-label", "class": "orgProperty"}, 0] }
    }}),
  marks: schema.spec.marks,
  doc: {
    content: "(block | org_property)+"
  }
})

```

But the dom structure

```auto
<div data-label="property-label" class="orgProperty">
    <p>:Name:</p><p>Item 1</p>
</div>

```

is stilled parsed into

```auto
<p>:Name:</p>
<p>Item</p>

```

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [July 7, 2019, 7:08am UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/9 "2019-07-07T07:08:45Z")

</div>

Your `doc: {content: "(block | org_property)+"}` text is just going to get ignored (`doc` doesn’t mean anything in a schema spec). You probably want to replace the `doc` node spec under `nodes` instead.

---

<div class="post-metadata">

### Author: ![jiewuza](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jiewuza/32/1113_2.png) [@jiewuza](https://discuss.prosemirror.net/u/jiewuza)
#### Post date: [July 8, 2019, 12:57am UTC](https://discuss.prosemirror.net/t/how-do-i-define-a-schema-nodespec-requiring-a-set-number-of-elements-within/1132/10 "2019-07-08T00:57:21Z")

</div>

Oops. I am new to prosemirror. But I like it. Thank you.
