From 3bd71e4618eafa8342e34d5fd3129b5731bde8f0 Mon Sep 17 00:00:00 2001 From: suyao Date: Wed, 29 Oct 2025 13:53:17 +0800 Subject: [PATCH] fix(yaml-front-matter): update start method regex to match exact YAML front matter format --- .../extensions/enhanced-horizontal-rule.ts | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/renderer/src/components/RichEditor/extensions/enhanced-horizontal-rule.ts diff --git a/src/renderer/src/components/RichEditor/extensions/enhanced-horizontal-rule.ts b/src/renderer/src/components/RichEditor/extensions/enhanced-horizontal-rule.ts deleted file mode 100644 index 8dac0f901f..0000000000 --- a/src/renderer/src/components/RichEditor/extensions/enhanced-horizontal-rule.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { mergeAttributes } from '@tiptap/core' -import { HorizontalRule } from '@tiptap/extension-horizontal-rule' - -/** - * Enhanced HorizontalRule extension that preserves leading spaces in markdown - * - * Standard Markdown allows 0-3 spaces before a horizontal rule (---, ***, ___) - * This extension preserves that indentation when serializing back to markdown - */ -export const EnhancedHorizontalRule = HorizontalRule.extend({ - addAttributes() { - return { - ...this.parent?.(), - // Store the number of leading spaces (0-3) - indentation: { - default: 0, - parseHTML: (element) => { - const indent = element.getAttribute('data-indentation') - return indent ? parseInt(indent, 10) : 0 - }, - renderHTML: (attributes) => { - if (!attributes.indentation) return {} - return { - 'data-indentation': attributes.indentation - } - } - } - } - }, - - parseHTML() { - return [ - { - tag: 'hr', - getAttrs: (element) => { - if (typeof element === 'string') return {} - - const htmlElement = element as HTMLElement - const indentAttr = htmlElement.getAttribute('data-indentation') - - return { - indentation: indentAttr ? parseInt(indentAttr, 10) : 0 - } - } - } - ] - }, - - renderHTML({ HTMLAttributes }) { - return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)] - }, - - // Custom markdown parsing to capture leading spaces - parseMarkdown(token) { - // The token.raw contains the original markdown including leading spaces - // Match 0-3 leading spaces before ---, ***, or ___ - const match = /^( {0,3})(?:---|___|\*\*\*)/.exec(token.raw || '') - const indentation = match ? match[1].length : 0 - - return { - type: this.name, - attrs: { - indentation - } - } - }, - - // Custom markdown serialization to restore leading spaces - renderMarkdown(node) { - const indentation = node.attrs?.indentation || 0 - const spaces = ' '.repeat(Math.min(indentation, 3)) // Max 3 spaces per spec - return spaces + '---\n\n' - } -})