mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 00:44:49 +00:00
Rich clipboard links carried their destination only in HTML, while the composer let textarea default paste insert the plain label. Convert linked fragments to Markdown at ingestion and replace the selected draft range through the existing editor command.
17 lines
661 B
TypeScript
17 lines
661 B
TypeScript
import TurndownService from "turndown";
|
|
|
|
const markdown = new TurndownService({ codeBlockStyle: "fenced", bulletListMarker: "-" });
|
|
|
|
/** Preserve destinations that the clipboard's plain-text representation cannot carry. */
|
|
export function readLinkedClipboardText(
|
|
clipboard: Pick<DataTransfer, "getData"> | null,
|
|
): string | null {
|
|
const html = clipboard?.getData("text/html");
|
|
if (!html) return null;
|
|
|
|
// Parse in a detached document. Clipboard markup is never mounted in the app.
|
|
const document = new DOMParser().parseFromString(html, "text/html");
|
|
if (!document.querySelector("a[href]")) return null;
|
|
return markdown.turndown(document.body);
|
|
}
|