Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing html with nested lists causes invalid doc structure #36

Open
Coding-Kiwi opened this issue May 13, 2023 · 6 comments
Open

Importing html with nested lists causes invalid doc structure #36

Coding-Kiwi opened this issue May 13, 2023 · 6 comments

Comments

@Coding-Kiwi
Copy link

See my comment #2 (comment)

If a <li> tag contains a <p> and a sublist <ul>, the ListItem Node wraps the content with an additional <p> tag.

The resulting json doc can be loaded into tiptap but as soon as you edit a list item, an Invalid content for node paragraph is thrown because there is now a <p> tag containing a <p> and <ul> tag which is not valid, because a <p> tag can only contain phrasing content.

@hivokas
Copy link

hivokas commented Jun 26, 2023

I'm seeing this issue as well.

> (new \Tiptap\Editor(['content' => '<p>List:</p><ul><li><p>bullet</p><ol><li><p>one</p></li></ol></li></ul>']))->getJSON()
= "{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"List:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"paragraph","content":[{"type":"text","text":"bullet"}]},{"type":"orderedList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"one"}]}]}]}]}]}]}]}"

> (new \Tiptap\Editor(['content' => '<p>List:</p><ul><li><p>bullet</p><ol><li><p>one</p></li></ol></li></ul>']))->getHTML()
= "<p>List:</p><ul><li><p><p>bullet</p><ol><li><p>one</p></li></ol></p></li></ul>"

Note how <p>bullet</p> becomes <p><p>bullet</p>.

@hivokas
Copy link

hivokas commented Jun 26, 2023

Similarly to @Coding-Kiwi, I've also noticed this issue while trying to migrate from HTML to JSON TipTap doc.

@hivokas
Copy link

hivokas commented Jun 26, 2023

@timoisik if you can take a look at this issue when you have time, it would be great.

@lukasleitsch
Copy link

I have the same issue with the sanitize method. Example:

$string = "<p>An example</p><ul><li><p>list item a</p><ul><li><p>list item b</p></li></ul></li></ul>";

$sanitizedHtml = (new Tiptap\Editor)->sanitize($string);

// output: <p>An example</p><ul><li><p><p>list item a</p><ul><li><p>list item b</p></li></ul></p></li></ul>

@lukasleitsch
Copy link

The workaround from @Coding-Kiwi in #2 (comment) solves the issue for me at this moment:

class TipTapListItem extends \Tiptap\Nodes\ListItem
{
    public static function wrapper($DOMNode)
    {
        return null;
    }
}

$string = "<p>An example</p><ul><li><p>list item a</p><ul><li><p>list item b</p></li></ul></li></ul>";

$sanitizedHtml = (new Tiptap\Editor([
        'extensions' => [
            new Tiptap\Extensions\StarterKit([
                'listItem' => false,
            ]),
            new TipTapListItem(),
        ],
    ]))->sanitize($string)

@timoisik
Copy link
Contributor

Hi, thank you for reporting this. As mentioned in #2 I would love to get rid of the wrapper function as well.

The workaround you are using here is like turn off the wrapper anyways, right? The issue here seems to be not just with the wrapper function but how the whole HTML is parsed in the DOMParser.php.

I would not plan to add support for schema-based normalization on the PHP side, because that would require essentially re-implementing a large part of ProseMirror’s document model. Instead, I would drop the wrapper function entirely and expect consumers of this library to send the correct Tiptap JSON up front.

I’m open to feedback or ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants