Skip to content

rohitnv09/paste-as-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paste-as-code

npm version license node

macOS clipboard Markdown output Linux and Windows

Copy a screenshot or image into clipboard, run one command, and paste back clean Markdown.

⚡ The Shortcut

pac -p -c
pac -cb -c

That is the whole magic trick:

  1. Copy a screenshot or image.
  2. Run pac -p -c or pac -cb -c.
  3. Paste the result into ChatGPT, Slack, Discord, GitHub issues or anywhere.

🚀 Install

npm install -g paste-as-code

Or try it without installing:

npx paste-as-code --help

Requires Node.js 20 or newer.

💡 Why It Exists

Screenshots are where useful text goes to become annoying.

paste-as-code removes the tiny, repetitive steps between “I can see this” and “I can use this”:

  • no manual typing
  • no file-path friction
  • no OCR configuration
  • no copy-paste cleanup
  • no Markdown wrapping
  • no need to paste screenshots or images into LLMs or agents; save tokens by sending the copied text from those images instead of the image itself

📋 Clipboard First

Copy any image to your clipboard and turn it into Markdown text.

pac -p
pac -cb
pac -cb -c

That means:

  • screenshot or any other image goes in on the clipboard
  • OCR runs immediately
  • clean Markdown comes back out
  • no file paths, no dragging, no waiting around

✨ Quick Start

🖥️ Clipboard Screenshot

On macOS, copy a screenshot to your clipboard, then run:

pac -cb -c

🖼️ Image File

If you already have a file:

pac screenshot.png

The output is Markdown by default:

```ts
const value: number = 1;
```

🧭 Command Reference

Command What it does
pac screenshot.png OCR an image file and print Markdown.
pac -cb Read a screenshot from the clipboard.
pac -cb -c Read clipboard image, OCR it, and copy Markdown back.
pac screenshot.png -r Print raw cleaned OCR text.
pac screenshot.png -l ts Force the Markdown fence language.
pac screenshot.png -k Keep edge-clipped lines that would otherwise be dropped.
pac screenshot.png --no-preprocess Skip image preprocessing if it hurts a specific screenshot.

Verbose forms are still supported too:

paste-as-code --clipboard --copy
paste-as-code screenshot.png --raw
paste-as-code screenshot.png --lang ts

✅ What It Handles Well

  • code screenshots
  • error messages
  • stack traces
  • terminal output
  • Discord and Slack snippets
  • macOS clipboard screenshots

🎯 Accuracy Notes

The OCR pipeline is tuned for code-like screenshots:

  • small images are upscaled
  • dark-theme screenshots are inverted when needed
  • text is normalized and sharpened before OCR
  • clipped top/bottom lines can be dropped automatically
  • code-friendly Tesseract settings preserve spacing and avoid aggressive dictionary correction

If a specific screenshot gets worse after preprocessing, use:

pac screenshot.png --no-preprocess

If you want to keep clipped lines anyway:

pac screenshot.png --keep-clipped

🧩 Platform Notes

  • File input works anywhere the package and native dependencies install successfully.
  • Clipboard image input is currently macOS-only.
  • Stay tuned for Linux and Windows clipboard support.

🛠️ Development

npm install
npm run typecheck
npm test
npm run build

Manual OCR smoke test:

npm run test:ocr -- screenshot.png

📦 Release

This repo is published to npm as paste-as-code.

If it saves you time, starring the repo helps other developers find it too.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors