diff --git a/packages/editor/src/extensions/outline-list/outline-list.ts b/packages/editor/src/extensions/outline-list/outline-list.ts index 22b780d94f..bc9037231b 100644 --- a/packages/editor/src/extensions/outline-list/outline-list.ts +++ b/packages/editor/src/extensions/outline-list/outline-list.ts @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +import { Fragment } from "@tiptap/pm/model"; import { getParentAttributes } from "../../utils/prosemirror.js"; import { Node, mergeAttributes, wrappingInputRule } from "@tiptap/core"; @@ -56,7 +57,7 @@ export const OutlineList = Node.create({ group: "block list", - content: `${outlineListItemName}+`, + content: `(${outlineListItemName}|listItem)+`, parseHTML() { return [ @@ -123,12 +124,41 @@ export const OutlineList = Node.create({ ]; }, addNodeView() { - return ({ node, HTMLAttributes }) => { + return ({ editor, node, getPos, HTMLAttributes }) => { const ul = document.createElement("ul"); ul.classList.add("outline-list"); if (node.attrs.textDirection) ul.dir = node.attrs.textDirection; for (const key in HTMLAttributes) ul.setAttribute(key, HTMLAttributes[key]); + + const processNestedNodes = (parentNode: Fragment, parentPos: number) => { + parentNode.forEach((child, offset) => { + const childPos = parentPos + offset + 1; + if ( + child.type.name === "bulletList" || + child.type.name === "orderedList" + ) { + editor.commands.command(({ tr }) => { + tr.setNodeMarkup(childPos, editor.schema.nodes.outlineList); + return true; + }); + } + if (child.type.name === "listItem") { + editor.commands.command(({ tr }) => { + tr.setNodeMarkup(childPos, editor.schema.nodes.outlineListItem); + return true; + }); + } + processNestedNodes(child.content, childPos); + }); + }; + + if (typeof getPos === "function") { + processNestedNodes(node.content, getPos()); + } else { + processNestedNodes(node.content, Number(getPos)); + } + return { dom: ul, contentDOM: ul