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

markdown task list not transform to todolist #3871

Open
tomdyqin opened this issue Dec 19, 2024 · 1 comment · May be fixed by #3872
Open

markdown task list not transform to todolist #3871

tomdyqin opened this issue Dec 19, 2024 · 1 comment · May be fixed by #3872
Labels
bug Something isn't working

Comments

@tomdyqin
Copy link
Contributor

tomdyqin commented Dec 19, 2024

Description

markdown task list not transform to todolist

Reproduction URL

No response

Reproduction steps

1. Copy plain text '- [x] xxx'
2. Click on 'plate editor'
3. Paste ...
4. See it transform to '<listitem>xxx</listitem>' 
expect '<listitem><todolist>xxx</todolist></listitem>

solution

// plate/packages/markdown/src/lib/remark-slate/remarkDefaultElementRules.ts
_node.children?.forEach((listItem) => {
    const listItemType = listItem.checked ? TodoListPlugin.key : options.editor.getType({ key: 'p' }); // <=== change type
    if (!listItem.children) {
      listItems.push({
        children: remarkTransformElementChildren(listItem, options),
        checked: listItem.checked, // <=== change checked
        type: listItemType, // <=== change type
      });

      return listItems;
    }

    const [paragraph, ...subLists] = listItem.children;

    listItems.push({
      children: remarkTransformElementChildren(
        paragraph || '',
        options,
      ),
      indent,
      listStyleType,
      checked: listItem.checked,// <=== change checked
      type: listItemType, // <=== change type
    });

    subLists.forEach((subList) => {
      if (subList.type === 'list') {
        parseListItems(subList, listItems, indent + 1);
      } else {
        const result = remarkTransformNode(subList, options) as
          | TElement
          | TElement[];

        if (Array.isArray(result)) {
          listItems.push(...result.map(v => ({ ...v, indent: indent + 1 })));
        } else {
          listItems.push({ ...result, indent: indent + 1 });
        }
      }
    });
  });

Plate version

40.0.0

Slate React version

0.112.0

Screenshots

No response

Logs

No response

Browsers

No response

@tomdyqin tomdyqin added the bug Something isn't working label Dec 19, 2024
@tomdyqin tomdyqin linked a pull request Dec 19, 2024 that will close this issue
6 tasks
@tomdyqin
Copy link
Contributor Author

#3872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant