-
Notifications
You must be signed in to change notification settings - Fork 952
Prefer HTML pasteboard flavor in rich-text-to-markdown for hyperlinked text fidelity #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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*", $_)') | ||
|
Comment on lines
+24
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am concerned about that because if the editor works with both, and the person prefers to have Markdown instead of RTF, the editor will kind of force the user to make use of RTF. Right? The case I am thinking of here is Google Docs, where we can have blocks of code and want to paste Markdown inside a code block. I am not sure if it will respect that. Perhaps it is better to have a second Script Command to convert to RTF instead of doing two things with a single Script Command. What do you think? |
||
|
|
||
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are making changes to the Script Command originally created by someone else, it is nice to credit them too, in this case: yourself.