From 1bb195474992641d089db344b6208236e958cd39 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 23 Nov 2023 11:20:37 +0000 Subject: [PATCH] fix: Fixed new line bugging out in md <-> html conversion --- packages/nc-gui/components/cell/RichText.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/cell/RichText.vue b/packages/nc-gui/components/cell/RichText.vue index 0322b2c6f9..9fc06e3894 100644 --- a/packages/nc-gui/components/cell/RichText.vue +++ b/packages/nc-gui/components/cell/RichText.vue @@ -19,7 +19,16 @@ const props = defineProps<{ const emits = defineEmits(['update:value']) -const turndownService = new TurndownService() +const turndownService = new TurndownService({}) + +turndownService.addRule('lineBreak', { + filter: (node) => { + return node.nodeName === 'BR' + }, + replacement: () => { + return '
' + }, +}) turndownService.addRule('taskList', { filter: (node) => { @@ -90,7 +99,9 @@ const tiptapExtensions = [ const editor = useEditor({ extensions: tiptapExtensions, onUpdate: ({ editor }) => { - const markdown = turndownService.turndown(editor.getHTML()) + const markdown = turndownService + .turndown(editor.getHTML().replaceAll(/

<\/p>/g, '
')) + .replaceAll(/\n\n
\n\n/g, '
\n\n') vModel.value = markdown },