Skip to content

Repository files navigation

Pasteboard Markdown

A small macOS command-line tool that reads rich pasteboard content and writes Markdown. It uses Swift, Foundation, and AppKit only.

By integration the CLI tool into e.g. LaunchBar 6 (an example action is provided), you can have a workflow where you take copy some text from an app that is not supporting markdown export (e.g. Microsoft Teams AI summaries), run it through the LaunchBar 4 action, then paste it into an app that is not supporting rich text paste (e.g. Mattermost, Text-only editors).

Requirements

  • macOS 13 or newer
  • Swift 6 / Xcode 16 or newer

Build and test

swift build -c release
swift test

The executable is written to .build/release/pasteboard-markdown.

Usage

pasteboard-markdown [--stdout] [--clipboard] [--help]

With no flags, the tool replaces the pasteboard contents with Markdown. --stdout prints the result without changing the pasteboard. Combine --stdout --clipboard to do both.

Input preference is HTML, then RTF, then plain text. HTML is converted structurally. RTF preserves bold and italic font traits, paragraphs, and Cocoa text lists; unsupported RTF formatting is reduced to text. Plain text passes through unchanged.

Supported HTML

HTML Markdown
p, br paragraphs and hard line breaks
h1…h6 headings
strong, b, em, i emphasis
a links
ul, ol, li nested lists
blockquote block quotes
pre, code fenced and inline code
hr thematic breaks
table, tr, th, td GitHub-style tables

Container tags such as div, section, and article create blocks. Unknown tags are discarded while their text and supported descendants remain. Named basic HTML entities and numeric Unicode entities are decoded. The parser is deliberately not a browser-grade HTML renderer: CSS, images, scripts, styles, definition lists, and layout are not converted.

Install

make install

This installs the binary as ~/.local/bin/pasteboard-markdown. Override the prefix with make install PREFIX=/usr/local.

LaunchBar

make install-action

This installs both the binary and Pasteboard to Markdown.lbaction in ~/Library/Application Support/LaunchBar/Actions. In LaunchBar, run Pasteboard to Markdown. The action replaces the pasteboard, closes the normal LaunchBar interface, and shows a temporary LaunchBar large-type confirmation. It does not create Notification Center entries or expose the Markdown as LaunchBar result items. If LaunchBar does not notice the action immediately, open LaunchBar Index and rescan Actions.

The installer removes downloaded-file quarantine metadata from the copied action bundle. This avoids carrying archive metadata into LaunchBar's Actions directory.

The wrapper expects the default binary path ~/.local/bin/pasteboard-markdown. If you use another PREFIX, edit Contents/Scripts/default.js in the action accordingly.

Design limits

The converter targets predictable pasteboard fragments, not arbitrary web-page conversion. Its supported subset and fallback order are an explicit compatibility contract. Tests cover HTML and RTF conversion, Unicode, pasteboard type preference, and pasteboard replacement.

License

0BSD. It permits use, modification, and redistribution without attribution requirements.

About

Mac OS CLI tool to convert HTML/Rich Text on clipboard to Markdown on clipboard

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages