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

The ol and ul lists are broken when editor content is created from markdown #76

Open
lorcan-codes opened this issue Dec 14, 2023 · 2 comments

Comments

@lorcan-codes
Copy link

lorcan-codes commented Dec 14, 2023

Going to new line is broken on ordered and numbered lists (as well as nested lists).

There are numbered list, clicking enter should add number in new line as well. Instead an empty space is added.

I get the same issue with remark-slate-transformer. Maybe there is an issue with markdown serialization? I have recored the video below from remark-slate-transformer demo website. But I get exactly same issue in our internal editor using remark-slate. I would really appreciate if you have any input why this might be happening.

markdown-to-slate-issue.mov
@KindaCallam-io
Copy link

Did you ever find a solution for this?

@Naerriel
Copy link

Imo the issue is that listItem contains a paragraph. If the paragraph isn't there, the list behaves as expected.
I implemented a custom snippet that removes the paragraph.

function isListItem(node: Descendant): boolean {
  return "type" in node && node.type === "listItem";
}

function parseListItem(node: Element): Descendant {
  // Karol: https://github.com/hanford/remark-slate/issues/76
  // We ignore the paragraph inside the list item, because it breaks the newline behavior
  const textNodes = [];
  for (const child of node.children) {
    if ("type" in child && child.type === "paragraph") {
      textNodes.push(...child.children);
    } else {
      textNodes.push(child);
    }
  }
  return { ...node, children: textNodes };
}

const isText = (node: Descendant): node is Text => "text" in node;

export function removeParagraphsFromListItems(
  nodes: Descendant[],
): Descendant[] {
  return nodes.map((node: Descendant) => {
    if (isText(node)) {
      return node;
    }
    if (isListItem(node)) {
      return parseListItem(node);
    }
    const children = "children" in node ? node.children : [];
    return {
      ...node,
      children: removeParagraphsFromListItems(children),
    };
  });
}

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

3 participants