aboutsummaryrefslogtreecommitdiff
path: root/highlight_code.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-02-11 23:32:00 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-02-11 23:32:00 +0100
commit39d40e287e835619bd753132b77be188b9d18b18 (patch)
tree7c9551f05d6caf7828a1e330bdf4f2c1734e48a4 /highlight_code.py
downloadrcheatsheet-39d40e287e835619bd753132b77be188b9d18b18.tar.gz
rcheatsheet-39d40e287e835619bd753132b77be188b9d18b18.zip
add tooling for R Cheatsheet
Diffstat (limited to 'highlight_code.py')
-rwxr-xr-xhighlight_code.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/highlight_code.py b/highlight_code.py
new file mode 100755
index 0000000..d708fd2
--- /dev/null
+++ b/highlight_code.py
@@ -0,0 +1,29 @@
+#!/bin/env python3
+
+import os
+import re
+import subprocess
+
+code_format = "```{0}\n{1}\n```"
+code_re = re.compile("<c (.*)>(.*)<\/c>")
+
+def main():
+ while True:
+ try:
+ s = input()
+ except EOFError as e:
+ break
+ m = re.search(code_re, s)
+ if m:
+ pandoc = subprocess.Popen(["pandoc","-f", "markdown", "-"],
+ universal_newlines=True, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ code, err = pandoc.communicate(input=code_format.format(m.group(1), m.group(2)))
+ pandoc.kill()
+ s = re.sub(code_re, code, s)
+ s = s.replace('\n', '')
+ print(s)
+
+
+if __name__ == "__main__":
+ main()