a tool for shared writing and social publishing
1import { getBlocksAsHTML } from "src/utils/getBlocksAsHTML";
2import { htmlToMarkdown } from "src/htmlMarkdownParsers";
3import { Replicache } from "replicache";
4import type { ReplicacheMutators } from "src/replicache";
5import { Block } from "components/Blocks/Block";
6
7export async function copySelection(
8 rep: Replicache<ReplicacheMutators>,
9 sortedSelection: Block[],
10) {
11 let html = await getBlocksAsHTML(rep, sortedSelection);
12 const data = [
13 new ClipboardItem({
14 ["text/html"]: new Blob([html.join("\n")], { type: "text/html" }),
15 "text/plain": new Blob([htmlToMarkdown(html.join("\n"))], {
16 type: "text/plain",
17 }),
18 }),
19 ];
20 await navigator.clipboard.write(data);
21}