From 1a864e96c115cefa6aa4965210ebf44d60cf0690 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 1 Jan 2018 04:46:37 -0800 Subject: adjust #eval to execute a shell command rather than execute one program also set up pandoc to include a bit of style information, currently located at headers.html TODO plans include configurable headers for a page, but not right now --- generator/generate.py | 11 ++++++++--- headers.html | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 headers.html 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 + '
' + evald_text + '
\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): diff --git a/headers.html b/headers.html new file mode 100644 index 0000000..de5f7ec --- /dev/null +++ b/headers.html @@ -0,0 +1,21 @@ + -- cgit v1.1