Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Created October 11, 2014 15:51
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 n8henrie/752f438caa266f8a639f to your computer and use it in GitHub Desktop.
Save n8henrie/752f438caa266f8a639f to your computer and use it in GitHub Desktop.
Uses pandoc to change all .md to .rst and vice-versa in a given directory tree.
#!/bin/bash -e
# toggle_docs.sh
# Uses pandoc to change all .md to .rst and vice-versa in a given directory tree.
# I don't really care for .rst, but PyPI needs it.
if [ "$(find . -iname "*.md")" ] && [ "$(find . -iname "*.rst")" ]; then
echo "Both .md and .rst filetypes exist, please make it so only one of two is there."
elif [ ! "$(find . -iname "*.md")" ] && [ ! "$(find . -iname "*.rst")" ]; then
echo "Neither .md or .rst filetypes exist, you should have one or the other."
else
# Do the converstion
if [ "$(find . -iname "*.md")" ]; then
for f in $(find . -iname "*.md"); do pandoc --from=markdown --to=rst "$f" > "${f%md}rst"; rm "$f"; done
elif [ "$(find . -iname "*.rst")" ]; then
for f in $(find . -iname "*.rst"); do pandoc --from=rst --to=markdown "$f" > "${f%rst}md"; rm "$f"; done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment