From 3c35b026c2f2d8b01347530eaaf883a39d3622d7 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Sat, 23 Dec 2023 10:49:26 +0200 Subject: [PATCH] fix: correct conversion of checklists Fixes #255 --- src/examples/basics.tsx | 23 ++++++++++++++++++++++- src/plugins/lists/MdastListItemVisitor.ts | 7 ++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/examples/basics.tsx b/src/examples/basics.tsx index e2f15ec5..faba8ed8 100644 --- a/src/examples/basics.tsx +++ b/src/examples/basics.tsx @@ -128,10 +128,31 @@ const listsMarkdown = ` * [x] Walk the dog * [ ] Watch movie * [ ] Have dinner with family + +... an all empty list + +* [ ] Walk the dog +* [ ] Watch movie +* [ ] Have dinner with family ` export function Lists() { - return + return ( + ( + + + + ) + }) + ]} + /> + ) } export function Table() { diff --git a/src/plugins/lists/MdastListItemVisitor.ts b/src/plugins/lists/MdastListItemVisitor.ts index 437ea67a..83f03c32 100644 --- a/src/plugins/lists/MdastListItemVisitor.ts +++ b/src/plugins/lists/MdastListItemVisitor.ts @@ -1,10 +1,11 @@ -import { $createListItemNode } from '@lexical/list' +import { $createListItemNode, ListNode } from '@lexical/list' import * as Mdast from 'mdast' import { MdastImportVisitor } from '../../importMarkdownToLexical' export const MdastListItemVisitor: MdastImportVisitor = { testNode: 'listItem', - visitNode({ mdastNode, actions }) { - actions.addAndStepInto($createListItemNode(mdastNode.checked ?? undefined)) + visitNode({ mdastNode, actions, lexicalParent }) { + const isChecked = (lexicalParent as ListNode).getListType() === 'check' ? mdastNode.checked ?? false : undefined + actions.addAndStepInto($createListItemNode(isChecked)) } }