How can I copy lists from tiptap to external programs? #4550
Unanswered
Coding-Kiwi
asked this question in
Questions & Help
Replies: 1 comment
-
As expected it broke, here is a shorter, updated version: import { Extension } from '@tiptap/core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
/**
* this is so that bullet lists are copied as such
*/
export const ClipboardExtension = Extension.create({
name: 'scribeClipboardTextSerializer',
addProseMirrorPlugins() {
return [
new Plugin({
key: new PluginKey('scribeClipboardTextSerializer'),
props: {
clipboardTextSerializer: (slice) => {
const serialize = (node, depth = 0) => {
let result = ''
node.forEach(child => {
if (child.type.name === 'listItem') {
result += `${' '.repeat(depth)}- ${child.textContent}\n`
if (child.childCount > 1) {
result += serialize(child, depth + 1)
}
} else {
result += serialize(child, depth)
}
})
return result
}
const fragment = slice.content
return serialize(fragment)
},
},
}),
];
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
lets say I have a simple bullet list
https://tiptap.dev/examples/default
when I select the list and hit copy and paste it in any other program i get
How can I achieve that the copied text is
instead?
I tried using an extension like this:
but this code feels like it could break as soon as I update tiptap the next time
Beta Was this translation helpful? Give feedback.
All reactions