Browse Source

fix: Fixed new line bugging out in md <-> html conversion

pull/7046/head
Muhammed Mustafa 1 year ago
parent
commit
1bb1954749
  1. 15
      packages/nc-gui/components/cell/RichText.vue

15
packages/nc-gui/components/cell/RichText.vue

@ -19,7 +19,16 @@ const props = defineProps<{
const emits = defineEmits(['update:value']) const emits = defineEmits(['update:value'])
const turndownService = new TurndownService() const turndownService = new TurndownService({})
turndownService.addRule('lineBreak', {
filter: (node) => {
return node.nodeName === 'BR'
},
replacement: () => {
return '<br />'
},
})
turndownService.addRule('taskList', { turndownService.addRule('taskList', {
filter: (node) => { filter: (node) => {
@ -90,7 +99,9 @@ const tiptapExtensions = [
const editor = useEditor({ const editor = useEditor({
extensions: tiptapExtensions, extensions: tiptapExtensions,
onUpdate: ({ editor }) => { onUpdate: ({ editor }) => {
const markdown = turndownService.turndown(editor.getHTML()) const markdown = turndownService
.turndown(editor.getHTML().replaceAll(/<p><\/p>/g, '<br />'))
.replaceAll(/\n\n<br \/>\n\n/g, '<br>\n\n')
vModel.value = markdown vModel.value = markdown
}, },

Loading…
Cancel
Save