Skip to content

Commit 36bca07

Browse files
committed
Copy markdown to clipboard with custom mime type
Plain text is also copied to the clipboard for pasting into external apps, like a terminal or code editor. Paste listeners within the site can detect the text/x-gfm mime type and choose to paste the markdown formatted selection instead.
1 parent 6ca65b3 commit 36bca07

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

quote-selection.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ function onCopy(event: ClipboardEvent) {
5858
} catch (err) {
5959
return
6060
}
61-
const quoted = extractQuote(selection.toString(), range, true)
61+
62+
const text = selection.toString()
63+
const quoted = extractQuote(text, range, true)
6264
if (!quoted) return
6365

64-
transfer.setData('text/plain', quoted.selectionText)
66+
transfer.setData('text/plain', text)
67+
transfer.setData('text/x-gfm', quoted.selectionText)
6568
event.preventDefault()
6669

6770
selection.removeAllRanges()

0 commit comments

Comments
 (0)