Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Treat newlines as linebreaks when pasting as plaintext
Until now, every newline was transformed into a paragraph break when
pasting plaintext.

Instead, newlines will be treated as linebreaks. Two newlines in a row
will be treated as paragraph break.

Fixes: #3598

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Dec 30, 2022
commit 6bb265e64fa6a7c33bf89922bba9b7de1c16ea9e
12 changes: 7 additions & 5 deletions src/extensions/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ const Markdown = Extension.create({
return false
},
clipboardTextParser(str, $context, _, view) {
if (shiftKey) {
return
}
const parser = DOMParser.fromSchema(view.state.schema)
const doc = document.cloneNode(false)
const dom = doc.createElement('div')
dom.innerHTML = markdownit.render(str)
if (shiftKey) {
// Treat single newlines as linebreaks and double newlines as paragraph breaks when pasting as plaintext
dom.innerHTML = '<p>' + str.replaceAll('\n', '<br />').replaceAll('<br /><br />', '</p><p>') + '</p>'
} else {
dom.innerHTML = markdownit.render(str)
}

const parser = DOMParser.fromSchema(view.state.schema)
return parser.parseSlice(dom, { preserveWhitespace: true, context: $context })
},
},
Expand Down