diff --git a/src/renderer/src/components/RichEditor/extensions/yaml-front-matter.ts b/src/renderer/src/components/RichEditor/extensions/yaml-front-matter.ts index d5305bd09..addb06ebe 100644 --- a/src/renderer/src/components/RichEditor/extensions/yaml-front-matter.ts +++ b/src/renderer/src/components/RichEditor/extensions/yaml-front-matter.ts @@ -17,6 +17,9 @@ export const YamlFrontMatter = Node.create({ atom: true, draggable: false, + // Markdown token name for custom parsing + markdownTokenName: 'yamlFrontMatter', + addOptions() { return { HTMLAttributes: {} @@ -75,6 +78,30 @@ export const YamlFrontMatter = Node.create({ ] }, + // Parse markdown token to Tiptap JSON + parseMarkdown(token: any) { + // Extract YAML content from the token + // The content should be the raw YAML text between --- delimiters + const content = token.text || token.raw || '' + return { + type: this.name, + attrs: { + content: content.trim() + } + } + }, + + // Serialize Tiptap node to markdown + renderMarkdown(node: any) { + const content = node.attrs.content || '' + // If content doesn't end with ---, add it + const trimmedContent = content.trim() + if (trimmedContent && !trimmedContent.endsWith('---')) { + return trimmedContent + '\n---\n\n' + } + return trimmedContent ? trimmedContent + '\n\n' : '' + }, + addCommands() { return { insertYamlFrontMatter: