write cached pygments stylesheet to static
This commit is contained in:
parent
c6cd90001a
commit
5ea472e014
3 changed files with 27 additions and 6 deletions
|
@ -96,7 +96,11 @@ class ZonaBuilder:
|
|||
self.item_map = {
|
||||
item.source.resolve(): item for item in self.items
|
||||
}
|
||||
# print(item_map)
|
||||
# write code highlighting stylesheet
|
||||
pygments_style = zmd.get_style_defs(self.config)
|
||||
(self.layout.content / "static" / "pygments.css").write_text(
|
||||
pygments_style
|
||||
)
|
||||
for item in self.item_map.values():
|
||||
dst = item.destination
|
||||
# print(item)
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
type="text/css"
|
||||
media="all"
|
||||
/>
|
||||
<link
|
||||
href="/static/pygments.css"
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
media="all"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
|
|
@ -97,11 +97,7 @@ class ZonaRenderer(HTMLRenderer):
|
|||
except Exception:
|
||||
lexer = TextLexer(stripall=False) # type: ignore
|
||||
|
||||
formatter = HtmlFormatter(
|
||||
style=config.theme,
|
||||
nowrap=not config.wrap,
|
||||
noclasses=True,
|
||||
)
|
||||
formatter = get_formatter(self.config)
|
||||
highlighted = highlight(code, lexer, formatter) # type: ignore
|
||||
|
||||
return (
|
||||
|
@ -110,6 +106,14 @@ class ZonaRenderer(HTMLRenderer):
|
|||
)
|
||||
|
||||
|
||||
def get_formatter(config: ZonaConfig):
|
||||
c = config.markdown.syntax_highlighting
|
||||
formatter = HtmlFormatter(
|
||||
style=c.theme, nowrap=not c.wrap, nobackground=True
|
||||
)
|
||||
return formatter
|
||||
|
||||
|
||||
def md_to_html(
|
||||
content: str,
|
||||
config: ZonaConfig | None,
|
||||
|
@ -134,3 +138,10 @@ def md_to_html(
|
|||
item_map=item_map,
|
||||
)
|
||||
return renderer.render(ast)
|
||||
|
||||
|
||||
def get_style_defs(config: ZonaConfig) -> str:
|
||||
formatter = get_formatter(config)
|
||||
defs = formatter.get_style_defs("pre.code-block code")
|
||||
assert isinstance(defs, str)
|
||||
return defs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue