diff options
Diffstat (limited to 'generator')
-rw-r--r-- | generator/generate.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/generator/generate.py b/generator/generate.py index d94d085..60ac8f6 100644 --- a/generator/generate.py +++ b/generator/generate.py @@ -21,7 +21,11 @@ def replace_references(lines, file_dir): elif line.startswith("#eval "): # include results of system'ing that line try: - evald_text = subprocess.check_output(line[6:], shell=True).decode('utf-8') + command = line[6:].strip() + eval_p = subprocess.Popen(['bash', '-c', command], stdout=subprocess.PIPE, stdin=subprocess.PIPE, cwd=file_dir) + evald_text = eval_p.communicate()[0].decode('utf-8') + if evald_text is None or len(evald_text.strip()) == 0: + raise Exception("Evaluating `{}` produced no output".format(command)) result = result + '<pre>' + evald_text + '</pre>\n' except Exception as e: print("Error processing line {}:\n {}\nError: {}".format(i, line, e)) @@ -47,6 +51,8 @@ if __name__ == "__main__": page_cwd = page_path[:(md_source.rfind('/') + 1)] page_path = page_path[(md_source.rfind('/') + 1):] + headers_file = './headers.html' + compiled_dest = './generated/{}{}'.format(page_cwd, page_path) print("Source: {}\nPage path: {}\nDest file: {}".format(md_source, page_path, compiled_dest)) try: @@ -59,9 +65,8 @@ if __name__ == "__main__": if markdown_blob == None: print("Error compiling {}".format(md_source)) sys.exit(3) - print(markdown_blob) # now shove it all through pandoc - pandoc_proc = subprocess.Popen(['pandoc'], stdout=subprocess.PIPE, stdin=subprocess.PIPE) + pandoc_proc = subprocess.Popen(['pandoc', '-H', headers_file], stdout=subprocess.PIPE, stdin=subprocess.PIPE) html = pandoc_proc.communicate(markdown_blob.encode('utf-8'))[0] try: if not os.path.isdir('./generated/' + page_cwd): |