Created
September 7, 2021 18:05
-
-
Save dceddia/70438ca20b0ba352333c6b417f983b80 to your computer and use it in GitHub Desktop.
Drop this in your .zshrc/.bashrc, copy some Markdown to the clipboard, and run `mkemail`. Paste the HTML wherever you want. Requires `pandoc` installed (brew install pandoc).
This file contains 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
# Take a Markdown email from the clipboard or a file and turn it into HTML | |
function mkemail() { | |
# Either read from clipboard (default) or read from a file | |
if [[ -z $1 ]]; then | |
content=`pbpaste` | |
echo "Reading from clipboard" | |
else | |
content=`cat $1` | |
echo "Reading from file '$1'" | |
fi | |
# Extract the subject from the first line | |
subject=$(echo $content | head -n 1 | grep 'Subject:') | |
# If there was no subject, convert all of the content | |
# Otherwise, strip off the Subject and the blank line that follows | |
if [[ -z $subject ]]; then | |
echo $content | pandoc -f markdown-smart -t html-smart --wrap=none | sed -e 's/<pre><code>/<pre>/g' -e 's/<\/pre><\/code>/<\/pre>/g' | pbcopy | |
echo "HTML copied to clipboard" | |
else | |
echo $content | tail -n +2 | pandoc -f markdown-smart -t html-smart --wrap=none | sed -e 's/<pre><code>/<pre>/g' -e 's/<\/code><\/pre>/<\/pre>/g' | pbcopy | |
echo "Skipped first 2 lines" | |
echo "HTML copied to clipboard" | |
echo $subject | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment