implement syntax_highlighting.enabled

This commit is contained in:
Daniel Fichtinger 2025-07-03 02:03:33 -04:00
parent c1e377c94d
commit 0940472410
3 changed files with 9 additions and 15 deletions

View file

@ -96,11 +96,13 @@ class ZonaBuilder:
self.item_map = { self.item_map = {
item.source.resolve(): item for item in self.items item.source.resolve(): item for item in self.items
} }
# write code highlighting stylesheet # write code highlighting stylesheet
pygments_style = zmd.get_style_defs(self.config) if self.config.markdown.syntax_highlighting.enabled:
(self.layout.content / "static" / "pygments.css").write_text( pygments_style = zmd.get_style_defs(self.config)
pygments_style (self.layout.content / "static" / "pygments.css").write_text(
) pygments_style
)
for item in self.item_map.values(): for item in self.item_map.values():
dst = item.destination dst = item.destination
# print(item) # print(item)

View file

@ -37,11 +37,6 @@ class MarkdownConfig:
) )
@dataclass
class ThemeConfig:
name: str = "default"
@dataclass @dataclass
class BuildConfig: class BuildConfig:
clean_output_dir: bool = True clean_output_dir: bool = True
@ -53,15 +48,12 @@ IGNORELIST = [".git", ".env", "*/.marksman.toml"]
@dataclass @dataclass
class ZonaConfig: class ZonaConfig:
title: str = "Zona Blog" base_url: str = "/"
base_url: str = "https://example.com"
language: str = "en"
# dictionary where key is name, value is url # dictionary where key is name, value is url
sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"}) sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"})
# list of globs relative to content that should be ignored # list of globs relative to content that should be ignored
ignore: list[str] = field(default_factory=lambda: IGNORELIST) ignore: list[str] = field(default_factory=lambda: IGNORELIST)
markdown: MarkdownConfig = field(default_factory=MarkdownConfig) markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
theme: ThemeConfig = field(default_factory=ThemeConfig)
build: BuildConfig = field(default_factory=BuildConfig) build: BuildConfig = field(default_factory=BuildConfig)
blog: BlogConfig = field(default_factory=BlogConfig) blog: BlogConfig = field(default_factory=BlogConfig)

View file

@ -87,10 +87,10 @@ class ZonaRenderer(HTMLRenderer):
def render_fenced_code(self, element: FencedCode): def render_fenced_code(self, element: FencedCode):
assert self.config assert self.config
config = self.config.markdown.syntax_highlighting config = self.config.markdown.syntax_highlighting
if not config.enabled:
return super().render_fenced_code(element)
code = "".join(child.children for child in element.children) # type: ignore code = "".join(child.children for child in element.children) # type: ignore
lang = element.lang or "text" lang = element.lang or "text"
if not config.enabled:
return f"<pre><code>{code}</code></pre>"
try: try:
lexer = get_lexer_by_name(lang, stripall=False) lexer = get_lexer_by_name(lang, stripall=False)