Fixed regexes to properly parse image and shader file names.
This commit is contained in:
parent
6b39c396db
commit
7334c6461d
|
|
@ -9,8 +9,9 @@ latexEngine = "xelatex"
|
|||
outputPath = "."
|
||||
|
||||
if not os.path.exists(outputPath): os.makedirs(outputPath)
|
||||
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
||||
texBookPath = os.path.join(outputPath, "book.tex")
|
||||
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
||||
texBookPath = os.path.join(outputPath, "book.tex")
|
||||
texTemplatePath = os.path.join(outputPath, "mytemplate.latex")
|
||||
|
||||
chapters = []
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ def injectShaderBlocks( _folder, _text ):
|
|||
lines = _text.split('\n');
|
||||
for line in lines:
|
||||
if line.find('<div class=\"codeAndCanvas\"') >= 0:
|
||||
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*)\"></div>', r'\1', line.rstrip())
|
||||
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*?)\"(></div>| .+></div>)', r'\1', line.rstrip())
|
||||
shaderName,shaderExt = os.path.splitext(shaderFile)
|
||||
shaderPath = folder+"/"+shaderFile;
|
||||
|
||||
|
|
@ -34,6 +35,11 @@ def injectShaderBlocks( _folder, _text ):
|
|||
rta += line+'\n'
|
||||
return rta
|
||||
|
||||
# TODO: Properly resizing images that are too big.
|
||||
# Remove file names from captions for generated images.
|
||||
# Fix insertShaderBlocks to properly parse image file names for textures.
|
||||
|
||||
|
||||
d='.'
|
||||
folders = [os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))];
|
||||
folders.sort()
|
||||
|
|
@ -43,19 +49,20 @@ for folder in folders:
|
|||
fileString = originalChapter.read()
|
||||
|
||||
# Correct path for images
|
||||
imgPattern = r'(\!\[(.*)\]\()'
|
||||
subPattern = r'\1{0}/'.format(folder)
|
||||
imgPattern = r'(\!\[.*?\]\()(.*)'
|
||||
subPattern = r'\1' + folder + r'/\2'
|
||||
modifiedChapterString = re.sub(imgPattern, subPattern, fileString)
|
||||
modifiedChapterString = injectShaderBlocks(folder,modifiedChapterString)
|
||||
modifiedChapterPath = folder+'/tmp.md'
|
||||
with open(modifiedChapterPath, "w") as modifiedChapter:
|
||||
modifiedChapter.write(modifiedChapterString)
|
||||
modifiedChapter.write(modifiedChapterString)
|
||||
chapters.append(modifiedChapterPath)
|
||||
|
||||
|
||||
# # 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 = ["--template="+texTemplatePath, "--latex-engine="+latexEngine]
|
||||
latexOptions = ["--latex-engine="+latexEngine]
|
||||
outputOptions = ["--output={0}".format(pdfBookPath)]
|
||||
pandocCommand = ["pandoc"] + outputOptions + inputOptions + generalOptions + latexOptions
|
||||
|
|
@ -74,14 +81,14 @@ for flag in generalOptions+latexOptions:
|
|||
texOutputOptions = ["--output={0}".format(texBookPath)]
|
||||
texPandocCommand = ["pandoc"] + texOutputOptions + inputOptions + generalOptions + latexOptions
|
||||
returnCode = subprocess.call(texPandocCommand)
|
||||
if returnCode == 0:
|
||||
if returnCode == 0:
|
||||
print "Successful building of {0}".format(texBookPath)
|
||||
else:
|
||||
print "Error in building of {0}".format(texBookPath)
|
||||
|
||||
# Call pandoc
|
||||
returnCode = subprocess.call(pandocCommand)
|
||||
if returnCode == 0:
|
||||
if returnCode == 0:
|
||||
print "Successful building of {0}".format(pdfBookPath)
|
||||
else:
|
||||
print "Error in building of {0}".format(pdfBookPath)
|
||||
print "Error in building of {0}".format(pdfBookPath)
|
||||
|
|
|
|||
Loading…
Reference in New Issue