|
|
|
@ -10,25 +10,30 @@ latexEngine = "xelatex"
|
|
|
|
|
# Output path
|
|
|
|
|
outputPath = "."
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(outputPath): os.makedirs(outputPath)
|
|
|
|
|
if not os.path.exists(outputPath):
|
|
|
|
|
os.makedirs(outputPath)
|
|
|
|
|
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
|
|
|
|
texBookPath = os.path.join(outputPath, "book.tex")
|
|
|
|
|
|
|
|
|
|
chapters = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def injectShaderBlocks(_folder, _text):
|
|
|
|
|
rta = ""
|
|
|
|
|
lines = _text.split('\n');
|
|
|
|
|
lines = _text.split('\n')
|
|
|
|
|
for line in lines:
|
|
|
|
|
if line.find('<div class=\"codeAndCanvas\"') >= 0:
|
|
|
|
|
shaderTextureResults = re.findall(r'<div class=\"codeAndCanvas\" data=\".*\" data-imgs=\"(.*)\"></div>', line.rstrip())
|
|
|
|
|
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*?)\"(>| .+>)</div>', r'\1', line.rstrip())
|
|
|
|
|
shaderTextureResults = re.findall(
|
|
|
|
|
r'<div class=\"codeAndCanvas\" data=\".*\" data-imgs=\"(.*)\"></div>', line.rstrip())
|
|
|
|
|
shaderFile = re.sub(
|
|
|
|
|
r'<div class=\"codeAndCanvas\" data=\"(.*?)\"(>| .+>)</div>', r'\1', line.rstrip())
|
|
|
|
|
|
|
|
|
|
shaderName, shaderExt = os.path.splitext(shaderFile)
|
|
|
|
|
|
|
|
|
|
shaderPath = folder+"/"+shaderFile;
|
|
|
|
|
shaderPath = folder + "/" + shaderFile
|
|
|
|
|
if shaderTextureResults:
|
|
|
|
|
shaderTexturePaths = map (lambda f: folder+"/"+f, shaderTextureResults[0].split(","))
|
|
|
|
|
shaderTexturePaths = map(
|
|
|
|
|
lambda f: folder + "/" + f, shaderTextureResults[0].split(","))
|
|
|
|
|
else:
|
|
|
|
|
shaderTexturePaths = []
|
|
|
|
|
|
|
|
|
@ -48,13 +53,16 @@ def injectShaderBlocks( _folder, _text ):
|
|
|
|
|
convertCommand = "convert " + gifPath + " " + pngImage
|
|
|
|
|
print convertCommand
|
|
|
|
|
returnCode = subprocess.call(convertCommand, shell=True)
|
|
|
|
|
rta += re.sub(r'\!\[(.*)\]\((.*)\.gif\)', r'![\1](\2-0.png)', line) + '\n'
|
|
|
|
|
rta += re.sub(r'\!\[(.*)\]\((.*)\.gif\)',
|
|
|
|
|
r'![\1](\2-0.png)', line) + '\n'
|
|
|
|
|
else:
|
|
|
|
|
rta += line + '\n'
|
|
|
|
|
return rta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d = '.'
|
|
|
|
|
folders = [os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))];
|
|
|
|
|
folders = [os.path.join(d, o) for o in os.listdir(
|
|
|
|
|
d) if os.path.isdir(os.path.join(d, o))]
|
|
|
|
|
folders.sort()
|
|
|
|
|
for folder in folders:
|
|
|
|
|
if os.path.isfile(folder + '/README.md'):
|
|
|
|
@ -65,19 +73,22 @@ for folder in folders:
|
|
|
|
|
imgPattern = r'(\!\[.*?\]\()(.*)'
|
|
|
|
|
subPattern = r'\1' + folder + r'/\2'
|
|
|
|
|
modifiedChapterString = re.sub(imgPattern, subPattern, fileString)
|
|
|
|
|
modifiedChapterString = injectShaderBlocks(folder, modifiedChapterString)
|
|
|
|
|
modifiedChapterString = injectShaderBlocks(
|
|
|
|
|
folder, modifiedChapterString)
|
|
|
|
|
modifiedChapterPath = folder + '/tmp.md'
|
|
|
|
|
with open(modifiedChapterPath, "w") as modifiedChapter:
|
|
|
|
|
modifiedChapter.write(modifiedChapterString)
|
|
|
|
|
chapters.append(modifiedChapterPath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Set up the appropriate options for the pandoc command
|
|
|
|
|
# Set up the appropriate options for the pandoc command
|
|
|
|
|
inputOptions = chapters
|
|
|
|
|
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone", "--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"] #
|
|
|
|
|
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone",
|
|
|
|
|
"--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"]
|
|
|
|
|
latexOptions = ["--latex-engine=" + latexEngine]
|
|
|
|
|
outputOptions = ["--output={0}".format(pdfBookPath)]
|
|
|
|
|
pandocCommand = ["pandoc"] + outputOptions + inputOptions + generalOptions + latexOptions
|
|
|
|
|
pandocCommand = ["pandoc"] + outputOptions + \
|
|
|
|
|
inputOptions + generalOptions + latexOptions
|
|
|
|
|
|
|
|
|
|
# Print out of the chapters being built and the flags being used
|
|
|
|
|
print "Generating {0} from:".format(pdfBookPath)
|
|
|
|
@ -91,7 +102,8 @@ for flag in generalOptions+latexOptions:
|
|
|
|
|
# printed out through pandoc aren't as useful as those printed
|
|
|
|
|
# directly from trying to build a PDF in TeXworks.
|
|
|
|
|
texOutputOptions = ["--output={0}".format(texBookPath)]
|
|
|
|
|
texPandocCommand = ["pandoc"] + texOutputOptions + inputOptions + generalOptions + latexOptions
|
|
|
|
|
texPandocCommand = ["pandoc"] + texOutputOptions + \
|
|
|
|
|
inputOptions + generalOptions + latexOptions
|
|
|
|
|
returnCode = subprocess.call(texPandocCommand)
|
|
|
|
|
if returnCode == 0:
|
|
|
|
|
print "Successful building of {0}".format(texBookPath)
|
|
|
|
|