From d40055bbda27915d1dbb67f5f13b1fef707cd07a Mon Sep 17 00:00:00 2001 From: Dmitry Ilvokhin Date: Sat, 10 Oct 2026 20:50:26 +0100 Subject: Support code formatting --- blog/highlight.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 blog/highlight.py (limited to 'blog/highlight.py') 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) -- cgit v1.3.1