From 39d40e287e835619bd753132b77be188b9d18b18 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 11 Feb 2017 23:32:00 +0100 Subject: add tooling for R Cheatsheet --- Makefile | 19 +++++++++++++++++++ highlight_code.py | 29 +++++++++++++++++++++++++++++ remove_table_width.sed | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 Makefile create mode 100755 highlight_code.py create mode 100644 remove_table_width.sed diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e895bd0 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +CSS=pandoc.css + +.PHONY: html, pdf, clean, all + +R_Cheatsheet.html: R_Cheatsheet.md + cat $< | ./highlight_code.py | pandoc -f markdown_github --css $(CSS) --highlight-style kate -o $@ -; + sed -i -f remove_table_width.sed $@ + +R_Cheatsheet.pdf: R_Cheatsheet.html + pandoc -f html -o $@ + +html: R_Cheatsheet.html + +pdf: R_Cheatsheet.pdf + +clean: + rm *.pdf *.html + +all: pdf html 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>") + +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() diff --git a/remove_table_width.sed b/remove_table_width.sed new file mode 100644 index 0000000..52dbb72 --- /dev/null +++ b/remove_table_width.sed @@ -0,0 +1,4 @@ +s//
/ +//d +/<\/colgroup>/d +//d -- cgit v1.2.3