summaryrefslogtreecommitdiff
path: root/blog/highlight.py
diff options
context:
space:
mode:
Diffstat (limited to 'blog/highlight.py')
-rw-r--r--blog/highlight.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/blog/highlight.py b/blog/highlight.py
new file mode 100644
index 0000000..e4d7b92
--- /dev/null
+++ b/blog/highlight.py
@@ -0,0 +1,23 @@
+import os
+from typing import cast, Callable
+
+from pygments.formatters import HtmlFormatter
+
+
+def get_style_defs() -> str:
+ # Workaround to avoid mypy to complain about untyped
+ # get_style_defs() call.
+ formatter = HtmlFormatter(style="bw")
+ selector = ".highlight"
+ f = cast(Callable[[str], str], formatter.get_style_defs)
+ return f(selector)
+
+
+class Highlight(object):
+ @staticmethod
+ def generate(basedir: str) -> None:
+ highligh = os.path.join(basedir, "highlight.css")
+
+ with open(highligh, mode='w') as f:
+ style = get_style_defs()
+ f.write(style)