I recently had to convert some markdown into plaintext and rather than use an online tool I wanted to do it locally. This is the solution I found.
Step 1: Install Pandoc
The Pandoc website has lots of options for installing Pandoc.
I’m on a Mac and use the Homebrew package manager, so I ran
brew install pandoc
Step 2: Convert the Markdown File
My markdown was in a file called myfile.md, so I ran the command
pandoc -f markdown -t plain myfile.md
This command outputs the plaintext to the standard output (the screen). We can capture this information in a file by appending > myfile.txt
pandoc -f markdown -t plain myfile.md > myfile.txt
Getting the Clipboard Involved
Since I’m on a Mac, I can use pbpaste to output the contents of the clipboard. This allows me to convert the contents of the clipboard with
pbpaste | pandoc -f markdown -t plain
Finally, if I want to copy the plain text into the clipboard I can use pbcopy to do this, so I run
pbpaste | pandoc -f markdown -t plain | pbcopy
which takes the markdown content in the clipboard, converts it to plain text, and copies the plain text back to the clipboard.
Leave a Reply