diff options
| author | Dmitry Ilvokhin <d@ilvokhin.com> | 2026-10-10 20:50:26 +0100 |
|---|---|---|
| committer | Dmitry Ilvokhin <d@ilvokhin.com> | 2026-10-10 20:50:26 +0100 |
| commit | d40055bbda27915d1dbb67f5f13b1fef707cd07a (patch) | |
| tree | dfaf1ab57b8738232c8b9de22c24004be7b1a6f9 /blog/highlight.py | |
| parent | a26f3db38f3b5b5a347afdfdcedb4dfc75d6a907 (diff) | |
| download | blog-d40055bbda27915d1dbb67f5f13b1fef707cd07a.tar.gz blog-d40055bbda27915d1dbb67f5f13b1fef707cd07a.tar.bz2 blog-d40055bbda27915d1dbb67f5f13b1fef707cd07a.zip | |
Diffstat (limited to 'blog/highlight.py')
| -rw-r--r-- | blog/highlight.py | 23 |
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) |