bustle/mobiledoc-kit

SectionParser fails on list section following section handled by parser plugin

Closed this issue · 2 comments

We're seeing Uncaught TypeError: Cannot read property 'append' of undefined errors when trying to parse markup pasted from Medium articles.

I've tracked it down to a <ul> following a node that is handled by a parser plugin (in our case a <figure> node) but only when the elements are wrapped in a container.

The container wrapper is the key point here. Without a wrapper each content section (<img>, <ul>) is passed to SectionParser independently and everything is handled fine, with the wrapper the whole <div> is passed to SectionParser which is where the error arises. This leads me to think that there could be some correlation with #648 but even so I don't think the parser should be erroring out.

A minimal markup test case looks like this where a parser plugin handles the <img> element:

<div>
  <img src="https://placehold.it/100x100">
  <ul>
    <li>LI One</li>
  </ul>
</div>

An example failing test can be seen in #657

This is the serialized sectionParser.state at the point _closeCurrentSection is called:

{
    "section": {
        "next": null,
        "prev": null,
        "type": "list-section",
        "isSection": true,
        "isMarkerable": false,
        "isNested": false,
        "isLeafSection": false,
        "_tagName": "ul",
        "isListSection": true,
        "items": {
            "head": null,
            "tail": null,
            "length": 0
        },
        "sections": {
            "head": null,
            "tail": null,
            "length": 0
        },
        "builder": {
            "markupCache": {}
        }
    },
    "markups": [],
    "text": "LI One"
}

The issue appears to be arising because the <li>'s text content has been set directly on the list-section rather than a list-item being created with the text.

_closeCurrentSection() then assumes that it has a markerable section which is where the error arises.

Closing as this has been resolved by recent updates to the section parser.