refac: unescape rich text input

This commit is contained in:
Timothy J. Baek 2024-10-19 02:50:49 -07:00
parent 7d322a7238
commit f6e7af346e

View File

@ -56,6 +56,16 @@
});
}
function unescapeMarkdown(text: string): string {
return text
.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, '$1') // unescape backslashed characters
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'");
}
// Method to convert markdown content to ProseMirror-compatible document
function markdownToProseMirrorDoc(markdown: string) {
return defaultMarkdownParser.parse(value || '');
@ -63,7 +73,8 @@
// Utility function to convert ProseMirror content back to markdown text
function serializeEditorContent(doc) {
return defaultMarkdownSerializer.serialize(doc);
const markdown = defaultMarkdownSerializer.serialize(doc);
return unescapeMarkdown(markdown);
}
// ---- Input Rules ----