Created
April 9, 2026 01:04
-
-
Save cedricvidal/596b40791ff3fe015c239c3148dcfbcb to your computer and use it in GitHub Desktop.
Converts Markdown in clipboard to a rich document in clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Detect if input is piped; otherwise, use clipboard content | |
| if [ -p /dev/stdin ]; then | |
| input=$(cat) | |
| else | |
| input=$(pbpaste) | |
| fi | |
| # Convert Markdown to HTML (disable YAML parsing and table extensions to avoid issues with --- horizontal rules) | |
| html=$(echo "$input" | pandoc -f markdown-yaml_metadata_block-simple_tables-multiline_tables-grid_tables -t html) | |
| # Optional: Pretty print Markdown | |
| echo "Pretty printed Markdown:" | |
| echo "------------------------" | |
| if command -v rich >/dev/null 2>&1; then | |
| echo "$input" | rich - -m | |
| else | |
| echo "$input" | |
| fi | |
| echo "------------------------" | |
| # Convert HTML to hex string (ensure no newlines) | |
| hex=$(echo -n "$html" | xxd -p | tr -d '\n') | |
| # Create temporary file for AppleScript (avoids shell escaping issues with long strings) | |
| tmpfile=$(mktemp) | |
| trap "rm -f '$tmpfile'" EXIT | |
| # Write AppleScript to temp file using printf (handles very long strings better than heredoc) | |
| printf 'set the clipboard to {text:" ", «class HTML»:«data HTML%s»}' "$hex" > "$tmpfile" | |
| # Execute AppleScript from file | |
| osascript "$tmpfile" | |
| # Notify user | |
| echo "Rich text has been copied to the clipboard. ✨" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment