From f6e7af346e5e6def565b0863e00d35af6d4606ae Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 19 Oct 2024 02:50:49 -0700 Subject: [PATCH] refac: unescape rich text input --- src/lib/components/common/RichTextInput.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index 19ff586df..885e14e72 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -56,6 +56,16 @@ }); } + function unescapeMarkdown(text: string): string { + return text + .replace(/\\([\\`*{}[\]()#+\-.!_>])/g, '$1') // unescape backslashed characters + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/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 ----