diff --git a/packages/client/src/tiptap/core/extensions/title.tsx b/packages/client/src/tiptap/core/extensions/title.tsx index c0712d5..386764b 100644 --- a/packages/client/src/tiptap/core/extensions/title.tsx +++ b/packages/client/src/tiptap/core/extensions/title.tsx @@ -74,7 +74,7 @@ export const Title = Node.create({ const $head = state.selection.$head; const titleNode = $head.node($head.depth); - const endPos = titleNode.firstChild.nodeSize + 1; + const endPos = ((titleNode.firstChild && titleNode.firstChild.nodeSize) || 0) + 1; dispatch(state.tr.insert(endPos, paragraph.create())); diff --git a/packages/client/src/tiptap/markdown/prosemirror-to-markdown/helpers.ts b/packages/client/src/tiptap/markdown/prosemirror-to-markdown/helpers.ts index c40548d..7b2d7d1 100644 --- a/packages/client/src/tiptap/markdown/prosemirror-to-markdown/helpers.ts +++ b/packages/client/src/tiptap/markdown/prosemirror-to-markdown/helpers.ts @@ -132,7 +132,9 @@ export function openTag(tagName, attrs) { str += Object.entries(attrs || {}) .map(([key, value]) => { if ((ignoreAttrs[tagName] || []).includes(key) || defaultAttrs[tagName]?.[key] === value) return ''; - + if (!['class', 'id'].includes(key) && !key.startsWith('data-')) { + key = `data-${key}`; + } return ` ${key}="${htmlEncode(value?.toString())}"`; }) .join(''); diff --git a/packages/client/src/tiptap/markdown/prosemirror-to-markdown/index.ts b/packages/client/src/tiptap/markdown/prosemirror-to-markdown/index.ts index 3232c27..06b719a 100644 --- a/packages/client/src/tiptap/markdown/prosemirror-to-markdown/index.ts +++ b/packages/client/src/tiptap/markdown/prosemirror-to-markdown/index.ts @@ -158,7 +158,7 @@ const SerializerConfig = { state.renderList(node, ' ', () => (node.attrs.bullet || '*') + ' '); }, [Text.name]: defaultMarkdownSerializer.nodes.text, - [Title.name]: renderCustomContainer('title'), + [Title.name]: renderHTMLNode('div', false, true, { class: 'title' }), }, };