@jczimm/slack-to-markdown
v1.1.2
Published
Convert Slack's clipboard format to Slack-compatible Markdown
Downloads
417
Readme
slack-to-markdown
Convert Slack's clipboard format to Slack-compatible Markdown.
What it does
When you copy formatted text from Slack, it stores the content in the slack/texty clipboard format. This library converts that content to Markdown that can be pasted into other applications (or back into Slack) and render correctly.
Usage
import { slackToMarkdown } from "@jczimm/slack-to-markdown";
// Pass the raw clipboard string - it handles parsing
const markdown = slackToMarkdown(clipboardData);
// Falls back to original string if not valid Slack format
slackToMarkdown("plain text") // => "plain text"Browser clipboard example
document.addEventListener("paste", (e) => {
const slackData = e.clipboardData?.getData("slack/texty");
if (slackData) {
e.preventDefault();
const markdown = slackToMarkdown(slackData);
// Insert markdown at cursor, or do whatever you want with it
}
});CLI
Reads Slack's clipboard format on stdin, writes Markdown to stdout. Input that isn't valid Slack clipboard data is passed through unchanged.
npx @jczimm/slack-to-markdown < clip.json
# installed globally
npm install -g @jczimm/slack-to-markdown
slack-to-markdown < clip.jsonslack-paste (macOS)
The package also installs slack-paste, which reads Slack's clipboard format off the macOS pasteboard so you can pipe it straight in:
slack-paste | slack-to-markdownWithout a global install, hand npx a shell so both commands resolve from a single package install:
npx -p @jczimm/slack-to-markdown sh -c 'slack-paste | slack-to-markdown'The pipe has to stay inside the quotes — outside them, your own shell takes it and pipes into a slack-to-markdown that isn't on PATH.
Copy the message, don't select the text. Open the message's overflow menu (the ⋯ button) and press ⌘C. Slack writes the slack/texty delta this tool reads only for a whole-message copy; drag-selecting the text and copying seems to come out as slack/html instead, which this tool doesn't handle.
pbpaste can't be used here — it only reads the plain-text, RTF and PostScript flavors, so it hands you the flattened text with the formatting already gone. Slack's clipboard data lives in a custom flavor, which Chromium-based apps (both the desktop app and Slack in a browser) pack into an org.chromium.web-custom-data pasteboard blob. slack-paste reads that via osascript and unpacks it.
It defaults to the slack/texty flavor. If a copy didn't produce that flavor, pass one explicitly or see what's actually on the clipboard:
slack-paste --list
slack-paste slack/htmlRunning tests
Requires Node.js 22+:
npm test