ProseMirror / prosemirror-markdown

ProseMirror Markdown integration
https://prosemirror.net
MIT License
344 stars 81 forks source link

Empty paragraph is added before custom node #41

Closed Trevald closed 4 years ago

Trevald commented 4 years ago

I 'm parsing git hub todo list (- [x]) to be replaced by a custom node. I've written a plugin to replace paragraphs with my custom node by just switching type on open and close tag: tokens[i - 1].type = "app_todo_open"

That doesn't seem to be a problem since the output from Markdown-it looks correct. But when running through MarkdownParser it generates an extra paragraph node before every app_todo node.

So without the custom node I get:

<ul>
  <li>
    <p>[ ] Not done</p>
  </li>
</ul>

And with the custom node:

<ul>
  <li>
    <p><br/></p>
    <p class="todo">Not done</p>
  </li>
</ul>

Breaks are set to false and when running it through only the markdown-it renderer I get the expected result:

<ul>
  <li>Not done</li>
</ul>

Any ideas what can cause this?

marijnh commented 4 years ago

I'm probably not going to debug this, but if you do and find a specific issue in this code, feel free to create a more precise bug report or pull request.

Trevald commented 4 years ago

Understandable, I haven't dived so deep in to the code. But I'll give that a try and see if I can find anything. If not I will try and come up with a way to remove the extra paragraphs. Thanks for your reply.

Trevald commented 4 years ago

So I've found that the problem is the schema used for list items. It's defined as:

list_item: {
  content: "paragraph block*",

Changing to (paragraph | app_todo) solves the parsing issue but creates other issues since the ListItem class used by the editor uses a another schema. So I think I'll just need to put in the work and create my own list- and list item nodes.

Closing this issue since it's not a bug but rather expected behaviour defined by the schema.