⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
import type { TiptapEditorHTMLElement } from "@tiptap/core";
import type { EditorView } from "@tiptap/pm/view";
export function pasteMarkdown(
view: EditorView,
event: ClipboardEvent,
): boolean {
// useEditor callbacks can retain a destroyed instance after recreation.
const editor = (view.dom as TiptapEditorHTMLElement).editor;
const clipboard = event.clipboardData;
// Rich clipboard content and code retain their native paste behavior.
if (
!editor ||
!editor.isEditable ||
!clipboard ||
clipboard.getData("text/html") ||
editor.isActive("codeBlock") ||
editor.isActive("code")
) {
return false;
}
const text = clipboard.getData("text/plain");
if (!text || !editor.markdown) return false;
// Leave single URLs to the issue-link and video-embed paste handlers.
if (/^https?:\/\/\S+$/i.test(text.trim())) return false;
const document = editor.markdown.parse(text);
const soleParagraph =
document.content?.length === 1 && document.content[0].type === "paragraph"
? document.content[0]
: undefined;
const soleInline =
soleParagraph?.content?.length === 1 ? soleParagraph.content[0] : undefined;
// GFM autolinks such as www.youtube.com must reach specialized URL handlers.
if (
soleInline?.text === text.trim() &&
soleInline.marks?.some((mark) => mark.type === "link")
)
return false;
const hasFormatting = (nodes: typeof document.content): boolean =>
(nodes ?? []).some(
(node) =>
(node.type !== "paragraph" && node.type !== "text") ||
Boolean(node.marks?.length) ||
hasFormatting(node.content),
);
if (!hasFormatting(document.content)) return false;
event.preventDefault();
editor.commands.insertContent(
soleParagraph?.content ?? document.content ?? [],
);
return true;
}