summaryrefslogtreecommitdiff
path: root/blog/highlight.py
diff options
context:
space:
mode:
authorDmitry Ilvokhin <d@ilvokhin.com>2026-10-10 20:50:26 +0100
committerDmitry Ilvokhin <d@ilvokhin.com>2026-10-10 20:50:26 +0100
commitd40055bbda27915d1dbb67f5f13b1fef707cd07a (patch)
treedfaf1ab57b8738232c8b9de22c24004be7b1a6f9 /blog/highlight.py
parenta26f3db38f3b5b5a347afdfdcedb4dfc75d6a907 (diff)
downloadblog-master.tar.gz
blog-master.tar.bz2
blog-master.zip
Support code formattingHEADmaster
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)