diff options
author | iximeow <me@iximeow.net> | 2018-01-01 04:46:37 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2018-01-01 04:46:37 -0800 |
commit | 1a864e96c115cefa6aa4965210ebf44d60cf0690 (patch) | |
tree | f52daf4e7e1faf8cc5812ebcfedd6357d9cc0f70 | |
parent | 22cdc1d261925125948000ea8382161121daf561 (diff) |
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
-rw-r--r-- | generator/generate.py | 11 | ||||
-rw-r--r-- | headers.html | 21 |
2 files changed, 29 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): diff --git a/headers.html b/headers.html new file mode 100644 index 0000000..de5f7ec --- /dev/null +++ b/headers.html @@ -0,0 +1,21 @@ +<style> +body { background-color: #d7d7dd; } +/* colors pulled from my current terminal config */ +.codebox .black { color: #2e3436; } +.codebox .red { color: #cc0000; } +.codebox .green { color: #4e9a06; } +.codebox .yellow { color: #c4a000; } +.codebox .blue { color: #3465a4; } +.codebox .purple { color: #75507b; } +.codebox .cyan { color: #06989a; } +.codebox .white { color: #d3d7cf; } +.codebox { + /* terminal foreground */ + color: #d3d7cf; + max-height: 512px; + width: 75%; + overflow: auto; + /* terminal background */ + background: #171717; +} +</style> |