(editor: Editor)
| 85 | }; |
| 86 | |
| 87 | const withListNormalization = (editor: Editor) => { |
| 88 | const { normalizeNode } = editor; |
| 89 | |
| 90 | editor.normalizeNode = (entry) => { |
| 91 | const [node, path] = entry; |
| 92 | |
| 93 | // Paragraphs, headings, and list items in list items should be stripped out |
| 94 | if (Element.isElement(node) && node.type === ElementType.ListItem) { |
| 95 | for (const [child, childPath] of Node.children(editor, path)) { |
| 96 | if ( |
| 97 | Element.isElement(child) && |
| 98 | (isTextType(child.type) || child.type === ElementType.ListItem) |
| 99 | ) { |
| 100 | Transforms.unwrapNodes(editor, { at: childPath }); |
| 101 | return; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Convert paragraphs and headings to list items if they are the children of a list |
| 107 | if (Element.isElement(node) && isListType(node.type)) { |
| 108 | for (const [child, childPath] of Node.children(editor, path)) { |
| 109 | if (Element.isElement(child) && isTextType(child.type)) { |
| 110 | Transforms.setNodes( |
| 111 | editor, |
| 112 | { type: ElementType.ListItem }, |
| 113 | { at: childPath } |
| 114 | ); |
| 115 | return; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Fall back to the original `normalizeNode` to enforce other constraints. |
| 121 | normalizeNode(entry); |
| 122 | }; |
| 123 | |
| 124 | return editor; |
| 125 | }; |
| 126 | |
| 127 | const isAtLineEnd = (editor: Editor, selection: Selection) => { |
| 128 | if (!selection) { |
no test coverage detected