Skip to content

Instantly share code, notes, and snippets.

@biboc
Last active July 25, 2018 08:35
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 biboc/c20fd032492b840df6f667be308f3238 to your computer and use it in GitHub Desktop.
Save biboc/c20fd032492b840df6f667be308f3238 to your computer and use it in GitHub Desktop.
Transform .asciidoc file to .md with recursive folder
#!/usr/bin/env python2
import glob
import os
from os.path import basename
OUT_DIRECTORY = "out"
os.system("rm -rf " + OUT_DIRECTORY)
os.system("mkdir -p " + OUT_DIRECTORY)
os.system("cp -R * " + OUT_DIRECTORY)
exclude = set([OUT_DIRECTORY])
for root, dirs, files in os.walk(".", topdown=True):
dirs[:] = [d for d in dirs if d not in exclude]
for file in files:
if file.endswith(".asciidoc"):
print("##################################################")
print(os.path.join(root, file))
print(file)
filePath = os.path.join(root, file)
cmd = "asciidoctor -b docbook -a leveloffset=+1 -o - " + filePath + \
" | pandoc --atx-headers --wrap=preserve -t markdown_strict -f docbook - > " + \
OUT_DIRECTORY+"/" + filePath + ".md"
print(cmd)
os.system(cmd)
for root, dirs, files in os.walk("out"):
for file in files:
if file.endswith(".asciidoc"):
os.system("rm " + os.path.join(root, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment