tiptap: fix transform title

This commit is contained in:
fantasticit 2022-06-03 14:17:14 +08:00
parent 0510303c7c
commit 5b6f211900
3 changed files with 5 additions and 3 deletions

View File

@ -74,7 +74,7 @@ export const Title = Node.create<TitleOptions>({
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()));

View File

@ -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('');

View File

@ -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' }),
},
};