From 3ff131fc5b4c407947a78f12a4cd5d41ab96bce7 Mon Sep 17 00:00:00 2001 From: Ali Rohde Date: Sat, 18 Apr 2026 13:10:57 -0400 Subject: [PATCH] Prefer HTML pasteboard flavor in rich-text-to-markdown for hyperlinked text fidelity Modern web sources (browsers, Gmail, Google Docs, Notion, Linear, etc.) place higher-fidelity HTML on the macOS pasteboard than RTF. Hyperlinked text in those sources arrives as real anchor tags in the HTML flavor, which pandoc cleanly renders as [label](url). The RTF flavor from the same sources often drops or mangles those links. The script now tries the HTML flavor first and falls back to the original RTF pipeline when HTML is not present, preserving existing behavior for all sources that only expose RTF. --- .../rich-text-clipboard-to-markdown.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/commands/conversions/rich-text-clipboard-to-markdown.sh b/commands/conversions/rich-text-clipboard-to-markdown.sh index 5bf7d5d1d..4e66d6379 100755 --- a/commands/conversions/rich-text-clipboard-to-markdown.sh +++ b/commands/conversions/rich-text-clipboard-to-markdown.sh @@ -6,7 +6,7 @@ # @raycast.title Rich Text to Markdown # @raycast.author Adam Zethraeus # @raycast.authorURL https://github.com/adam-zethraeus -# @raycast.description Convert rich text clipboard data to GitHub Flavored Markdown using Pandoc +# @raycast.description Convert rich text clipboard data (preserving hyperlinked text as [label](url)) to GitHub Flavored Markdown using Pandoc. Tries the HTML pasteboard flavor first, falls back to RTF. # # @raycast.icon 📝 # @@ -20,4 +20,19 @@ if ! command -v pandoc &> /dev/null; then fi export LC_CTYPE=UTF-8 + +# Prefer HTML: most modern web sources (browsers, Gmail, Google Docs, Notion, +# Linear, etc.) place higher-fidelity HTML on the pasteboard than RTF, and it +# preserves hyperlinked text as real anchor tags that pandoc renders as +# [label](url) in markdown. +html=$(osascript -e 'try' -e 'the clipboard as «class HTML»' -e 'on error' -e 'return ""' -e 'end try' 2>/dev/null \ + | perl -ne 'chomp; next unless s/^«data HTML//; s/»$//; print pack("H*", $_)') + +if [ -n "$html" ]; then + printf '%s' "$html" | pandoc --from=html --to=gfm | pbcopy + exit 0 +fi + +# Fall back to RTF for sources that only expose rich text (some native apps, +# older editors). This is the original behavior of the script. osascript -e 'the clipboard as «class RTF »' | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | pandoc --from=rtf --to=gfm | pbcopy