Skip to content

[Bug]: TaskItem loses checked state #78

Description

@lukasleitsch

PHP Version

8.4

Version

2.0.0

Bug Description

The DOMParser loses the state of task items when processing HTML. The HTML in the example below is the output of the TipTap editor. After parsing the HTML, the checked state of the items is lost.

<?php

require_once 'vendor/autoload.php';

use Tiptap\Core\DOMParser;
use Tiptap\Core\DOMSerializer;
use Tiptap\Nodes\TaskItem;
use Tiptap\Nodes\TaskList;

function test(?string $html): ?string
{
    $schema = new \Tiptap\Core\Schema([
        new Tiptap\Extensions\StarterKit,
        new Tiptap\Marks\Link,
        new TaskList,
        new TaskItem,
    ]);

    $document = new DOMParser($schema)->process($html);
    $processedHtml = new DOMSerializer($schema)->process($document);

    return $processedHtml;
}

// Test input HTML with checked tasks
$inputHtml = '<ul data-type="taskList"><li data-checked="true" data-type="taskItem"><label><input type="checkbox" checked="checked"><span></span></label><div><p>Task 1</p></div></li><li data-checked="false" data-type="taskItem"><label><input type="checkbox"><span></span></label><div><p>Task 2</p></div></li><li data-checked="false" data-type="taskItem"><label><input type="checkbox"><span></span></label><div><p>Task 3</p></div></li></ul><p></p>';

echo "Input HTML:\n";
echo $inputHtml . "\n\n";

echo "Output HTML:\n";
$output = test($inputHtml);
echo $output . "\n\n";

Expected Behavior

I would expect that the checked state is also present after the processing.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions