mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
Add markdown parsing and serialization for YAML front matter
- Add `markdownTokenName` property for custom parsing - Implement `parseMarkdown` to convert markdown tokens to Tiptap JSON - Implement `renderMarkdown` to serialize Tiptap nodes back to markdown format
This commit is contained in:
parent
a418b61230
commit
a66c0860b2
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user