Skip to content

Instantly share code, notes, and snippets.

@brianjking
Created January 8, 2016 16:38
Show Gist options
  • Save brianjking/e4a9176a05c0ec0ac40f to your computer and use it in GitHub Desktop.
Save brianjking/e4a9176a05c0ec0ac40f to your computer and use it in GitHub Desktop.
Convert Markdown to RST for Sphinx automatically using Pandoc - NEEDS TESTED. Obtained via: http://www.pythonbackend.com/topic/1268949527
#!/usr/bin/env python
import os
import subprocess
DOCUMENTATION_SOURCE_DIR = 'documentation/source/'
SOURCE_EXTENSION = '.md'
OUTPUT_EXTENSION = '.rst'
for _, __, filenames in os.walk(DOCUMENTATION_SOURCE_DIR):
for filename in filenames:
if filename.endswith('.md'):
filename_stem = filename.split('.')[0]
source_file = DOCUMENTATION_SOURCE_DIR + filename_stem + SOURCE_EXTENSION
output_file = DOCUMENTATION_SOURCE_DIR + filename_stem + OUTPUT_EXTENSION
command = 'pandoc -s {0} -o {1}'.format(source_file, output_file)
print(command)
subprocess.call(command.split(' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment