@@ 14,7 14,7 @@ tasks:
python -m venv env
. env/bin/activate
pip install -r blog/requirements.txt
- pip install install types-PyYAML types-jinja2 mypy
+ pip install install types-PyYAML types-jinja2 types-Pygments mypy
- typecheck: |
. env/bin/activate
@@ 20,6 20,7 @@
import os, datetime, collections, hashlib, pathlib, typing
import pygments.lexers, pygments.formatters, pygments.util
+import pandocfilters # type: ignore
os.chdir(os.path.abspath(os.path.dirname(__file__)))
from ssg import *
@@ 87,16 88,17 @@ def has_changed(p: Page) -> bool:
return not (p.outpath.exists() and cache.exists() and cache.read_text().strip() == content_key)
LANG_COMPAT = {"python-repl": "pycon", "txt": "text"}
-def pygments_filter(key, value, format, meta):
+def pygments_filter(key: str, value: PandocValue, format: str, meta: dict[str, typing.Any]) -> typing.Union[None, list[PandocElement], PandocElement]:
if format != "html5":
- return
+ return None
if key == "CodeBlock":
+ assert isinstance(value, list) and isinstance(value[0], list)
[[ident, classes, kvpairs], body] = value
assert ident == ""
assert kvpairs == []
assert len(classes) <= 1
if not classes:
- return
+ return None
[lang] = classes
try:
lexer = pygments.lexers.get_lexer_by_name(LANG_COMPAT.get(lang, lang))
@@ 105,6 107,7 @@ def pygments_filter(key, value, format, meta):
return
hl = pygments.highlight(body, lexer, pygments.formatters.HtmlFormatter(wrapcode=True, cssclass=f"highlight {lang}"))
return pandocfilters.RawBlock(format, hl)
+ return None
mdreader = PandocRenderer.markdown_reader(options=["--mathml", "--no-highlight"])
htmlwriter = PandocRenderer.html_writer(options=["--mathml", "--no-highlight"])
@@ 350,7 350,7 @@ class CacheRegistrationRenderer(Renderer):
self.cachedir = cachedir
self.meta_key = meta_key
- def _register(self, page):
+ def _register(self, page: Page) -> None:
assert self.meta_key in page.metadata
location_key, content_key = page.metadata[self.meta_key]
(self.cachedir / location_key).write_text(content_key)