Download src/utils/exportUtils.ts from algorembrant/rem-notepad: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/algorembrant/rem-notepad/resolve/main/src/utils/exportUtils.ts
- Command line
-
hf download hf://algorembrant/rem-notepad/src/utils/exportUtils.ts
-
curl -L -o exportUtils.ts https://huggingface.co/algorembrant/rem-notepad/resolve/main/src/utils/exportUtils.ts
1.72 kB
| import { FileNode } from '../lib/db'; | |
| /** | |
| * Extracts raw text from Lexical JSON payload if necessary, | |
| * then prepends emdash '— ' to each non-empty text line. | |
| */ | |
| export function formatContentForCopy(content: string): string { | |
| if (!content) return ''; | |
| let rawText = content; | |
| // If content is a Lexical JSON string | |
| try { | |
| const parsed = JSON.parse(content); | |
| if (parsed.root && parsed.root.children) { | |
| // Very basic extraction of paragraphs for copy buffer | |
| // In reality, you'd use Lexical's @lexical/text plugin or simple tree iteration | |
| rawText = parsed.root.children | |
| .map((p: any) => p.children?.map((n: any) => n.text).join('') || '') | |
| .join('\n'); | |
| } | |
| } catch (e) { | |
| // not JSON, fallback to rawText as is | |
| } | |
| const lines = rawText.split('\n'); | |
| const formattedLines = lines.map(line => { | |
| if (line.trim().length > 0) { | |
| return `— ${line}`; | |
| } | |
| return line; // Leave empty lines untouched | |
| }); | |
| return formattedLines.join('\n'); | |
| } | |
| export async function copyFilesContentToClipboard(files: FileNode[], idsToCopy: string[]) { | |
| const contentArray: string[] = []; | |
| const addContentRecursive = (nodeId: string) => { | |
| const node = files.find(f => f.id === nodeId); | |
| if (!node) return; | |
| if (node.type === 'file' && node.content) { | |
| contentArray.push(formatContentForCopy(node.content)); | |
| } | |
| const children = files.filter(f => f.parentId === nodeId); | |
| children.forEach(c => addContentRecursive(c.id)); | |
| }; | |
| for (const id of idsToCopy) { | |
| addContentRecursive(id); | |
| } | |
| if (contentArray.length > 0) { | |
| const combined = contentArray.join('\n\n'); | |
| await navigator.clipboard.writeText(combined); | |
| } | |
| } | |