Skip to content

Commit

Permalink
fix: correct conversion of checklists
Browse files Browse the repository at this point in the history
Fixes #255
  • Loading branch information
petyosi committed Dec 23, 2023
1 parent 606e0d7 commit 3c35b02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/examples/basics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <MDXEditor markdown={listsMarkdown} plugins={[listsPlugin()]} />
return (
<MDXEditor
markdown={listsMarkdown}
plugins={[
listsPlugin(),
diffSourcePlugin(),
toolbarPlugin({
toolbarContents: () => (
<DiffSourceToggleWrapper>
<UndoRedo />
</DiffSourceToggleWrapper>
)
})
]}
/>
)
}

export function Table() {
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/lists/MdastListItemVisitor.ts
Original file line number Diff line number Diff line change
@@ -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<Mdast.ListItem> = {
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))
}
}

0 comments on commit 3c35b02

Please sign in to comment.