UNPKG

@mkljczk/lexical-remark

Version:

This package contains Markdown helpers and functionality for Lexical using remark-parse.

17 lines (14 loc) 531 B
import { $createListItemNode, $isListNode } from '@lexical/list'; import type { LexicalNode } from 'lexical'; import { ListItem } from 'mdast'; import { Handler } from '../parser.js'; export const listItem: Handler<ListItem> = (node, parser) => { if (!$isListNode(parser.stack[parser.stack.length - 1] as LexicalNode)) { return; } const lexicalNode = $createListItemNode(); parser.push(lexicalNode); node.children.forEach((child) => parser.parse(child)); parser.pop(lexicalNode); parser.append(lexicalNode); };