Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBronosky/c2d609b721df3ecc771c4980e9f6b63f to your computer and use it in GitHub Desktop.
Save RichardBronosky/c2d609b721df3ecc771c4980e9f6b63f to your computer and use it in GitHub Desktop.
#!/bin/bash
convert_text(){
python3 -c 'import html, sys; [print(html.escape(l), end="") for l in sys.stdin]' | \
sed -E $'
1i\\\n<span style="-en-clipboard:true;"><br/></span><div style="-en-codeblock:true;"><div>\n
s, ,\&nbsp;,g
s,$,<br/>,
s,^<br/>$,<div><br/></div>,
$a\\\n</div></div>\n
'
}
convert_clipboard(){
osascript -e "set the clipboard to «data HTML$(pbpaste | hexdump -ve '1/1 "%.2x"')»"
}
main(){
pbpaste | convert_text | pbcopy
convert_clipboard
}
self_test(){
convert_text <$BASH_SOURCE
}
if [[ ${1:-} == "-t" ]]; then
self_test
else
main
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment