Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export function clipboardTextParser(
text: string,
$context: ResolvedPos,
plain: boolean,
view: EditorView
view: EditorView,
parseMarkdownOnPaste = true
): Slice {
if (!plain && isProbablyMarkdown(text)) {
if (!plain && parseMarkdownOnPaste && isProbablyMarkdown(text)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated comment: plain is true when content is pasted via ctrl+shift+v but false if pasted view right click > paste as plain text. I haven't found any answer for this yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plain is set by prosemirror I think. Might be worth investigating.

const node = ClipboardDOMParser.fromSchema(view.state.schema).parse(
new DOMParser().parseFromString(
markdowntoHTML(text, { allowDangerousHtml: false }),
Expand Down
15 changes: 14 additions & 1 deletion packages/editor/src/extensions/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import { EditorView } from "prosemirror-view";
export const Clipboard = Extension.create({
name: "clipboard",

addOptions() {
return {
parseMarkdownOnPaste: true
};
},

addProseMirrorPlugins() {
return [
new Plugin({
Expand All @@ -40,7 +46,14 @@ export const Clipboard = Extension.create({
this.editor.schema
),
transformCopied,
clipboardTextParser,
clipboardTextParser: (text, $context, plain, view) =>
clipboardTextParser(
text,
$context,
plain,
view,
this.options.parseMarkdownOnPaste
),
clipboardTextSerializer
}
})
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ const useTiptap = (
allowTableNodeSelection: true,
cellMinWidth: 50
}),
Clipboard,
Clipboard.configure({
parseMarkdownOnPaste: options.enableInputRules
}),
TableRow,
TableCell,
TableHeader,
Expand Down
Loading