Skip to content

feat: add Markdown/ZIP export and reorganize sources under src/#1

Merged
FuDesign2008 merged 1 commit into
mainfrom
feat/downloads-and-src-refactor
Apr 22, 2026
Merged

feat: add Markdown/ZIP export and reorganize sources under src/#1
FuDesign2008 merged 1 commit into
mainfrom
feat/downloads-and-src-refactor

Conversation

@FuDesign2008
Copy link
Copy Markdown
Owner

Summary

Inspired by upstream Evercoder/clipboard-inspector#16, this PR:

  • Adds Download as Markdown — a single self-contained .md file designed to be pasted directly into an AI chat
  • Adds Download as ZIP — structured archive based on Implement ZIP export feature for downloading clipboard data Evercoder/clipboard-inspector#16, improved to nest each clipboard entry under data-<index>/ so multiple DataTransfer entries no longer collide
  • Reorganizes sources under src/ — splits the 413-line index.jsx into 7 focused modules; index.js remains at the repo root as a build artifact so gh-pages -d . deployment keeps working
  • Fixes two pre-existing React warnings (class=className= on .cb-copy / .cb-entry)

See docs/refactor-2026-04.md for the full plan, trade-offs, and design rationale.

New project layout

src/
├── index.jsx                   # entry: render + paste/drop/dragover
├── ClipboardInspector.jsx      # main UI
├── extract-data.js             # DataTransfer/ClipboardItem extraction
├── mdn-urls.js                 # MDN link constants
└── download/
    ├── utils.js                # MIME, filename, and download helpers
    ├── markdown.js             # new: Download as Markdown
    └── zip.js                  # new: Download as ZIP (borrowed from #16)

Markdown export design

  • Header with timestamp, source kind, and per-section counts
  • One section per clipboard entry
  • Tables for .types / .items / .files
  • Text payloads rendered in fenced code blocks, with language inferred from the MIME type (text/htmlhtml, application/jsonjson, etc.)
  • Dynamic fence escaping: when content itself contains triple backticks, fences automatically grow to quadruple or longer so the document never breaks
  • Binary payloads described by name / type / human-readable size (no base64 embed, to keep the file small)

ZIP export improvements over Evercoder#16

  • Each clipboard entry gets its own data-<index>/ subfolder, avoiding the case where multiple DataTransfer items overwrite each other in types/ / items/ / files/
  • Shared helpers extracted to src/download/utils.js for reuse by the Markdown exporter

Test plan

  • npm install
  • npm run build — produces index.js (449.8kb)
  • npm run start — dev server on 127.0.0.1:8000 serves updated bundle
  • buildMarkdown() unit test — 14/14 assertions covering header metadata, section layout, MIME→language inference, binary description, human-readable sizes, and dynamic fence escaping
  • Lint — 0 errors
  • Manual: paste plain text → Download as Markdown → verify content
  • Manual: paste rich content (HTML + plain text) → Download as Markdown → verify both blocks appear with correct language hints
  • Manual: drop an image file → Download as ZIP → verify data-0/files/<name>.png exists and the bytes match
  • Manual: use Clipboard API paste → Download as ZIP → verify data-<n>/types/ structure

Compatibility

  • gh-pages -d . deployment keeps working: index.html, index.js, style.css remain at the repo root
  • index.js is regenerated on npm run build; banner updated to "auto-generated from src/, do not edit directly"
  • Bundle size: 260KB → 449.8KB (+190KB from jszip); acceptable for a purely client-side devtool

Follow-ups (not in this PR)

  • Optional: inline small images (<50KB) as base64 data URLs in the Markdown export so AIs can "see" them
  • Optional: add a "Copy Markdown to clipboard" button
  • Set up vitest and promote the ad-hoc buildMarkdown test script into a proper test suite

Made with Cursor

Inspired by upstream PR Evercoder#16.

Why:
- Users want to share clipboard snapshots with AI assistants, which
  works best as a single self-contained Markdown file.
- Users also want the raw bytes (text + binary files) for offline
  analysis or bug reports.
- The previous layout mixed source (index.jsx) with the build artifact
  (index.js) at the repo root, which was easy to edit by mistake.

What:
- Split index.jsx into a proper src/ tree:
    src/index.jsx                 entry (render + paste/drop/dragover)
    src/ClipboardInspector.jsx    main UI component
    src/extract-data.js           DataTransfer/ClipboardItem extraction
    src/mdn-urls.js               MDN link constants
    src/download/utils.js         shared MIME/filename/download helpers
    src/download/markdown.js      new: download as a single .md file
    src/download/zip.js           new: download as a structured ZIP
- Add "Download as Markdown" button: single .md with timestamp header,
  per-entry sections, tables for .types/.items/.files, fenced code
  blocks with language inferred from MIME, and dynamic fence escaping
  for content that itself contains triple backticks. Binary payloads
  are described by name/type/human-readable size.
- Add "Download as ZIP" button: structure based on Evercoder#16 (README.txt,
  metadata.json, types/, items/, files/ with manifests). Improves on
  Evercoder#16 by nesting each clipboard entry under data-<index>/, so multiple
  DataTransfer entries no longer collide.
- Decouple ClipboardInspector from the global render() via onReset and
  onPasteFromClipboard props.
- Fix pre-existing React warnings by changing class= to className= on
  .cb-copy and .cb-entry.
- Update package.json scripts to point at src/index.jsx, add jszip
  ^3.10.1 dependency, and rewrite README.md with the new layout and
  export formats.
- Keep index.html / index.js / style.css at the repo root so that
  `gh-pages -d .` deployment continues to work; the committed index.js
  is regenerated from src/ via `npm run build`.

Verified: npm run build (449.8kb), dev server smoke test on
127.0.0.1:8000, buildMarkdown unit test 14/14.

See docs/refactor-2026-04.md for the full plan and trade-offs.

Made-with: Cursor
@FuDesign2008 FuDesign2008 merged commit 6108d5a into main Apr 22, 2026
@FuDesign2008 FuDesign2008 deleted the feat/downloads-and-src-refactor branch April 22, 2026 07:28
FuDesign2008 added a commit that referenced this pull request Apr 22, 2026
The `Download as Markdown` / `Download as ZIP` buttons introduced in #1
used a Material-style filled look (saturated blue/green + white text)
that clashed with the project's Neo-Brutalism language (thick black
border, light background, black text, offset black shadow, yellow
`:active`). The white `color` also made `box-shadow: 0.1em 0.1em
currentColor` render as an invisible white shadow on the white page.

Make the two download buttons inherit the baseline `button{}` rules and
only override `background` for light-tinted semantic hints:

- `--md`  → `#cfe8ff` (light blue, black text, contrast ≈17:1)
- `--zip` → `#c8f7da` (light green, black text, contrast ≈18:1)

Border color, text color, offset shadow, and `:active` yellow now come
from the baseline, so the three buttons (`Go back` + two downloads)
share the same visual grammar. Net -14 lines of CSS; no JS or markup
changes; `index.js` is byte-identical to main.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant