From 3037aa88d87609a6853561a254fc77421d596861 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sun, 6 Jul 2025 21:09:55 -0400 Subject: [PATCH] added math frontmatter option --- src/zona/builder.py | 21 +++++++-------------- src/zona/markdown.py | 5 ++++- src/zona/metadata.py | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/zona/builder.py b/src/zona/builder.py index 8f7a3dc..31140c8 100644 --- a/src/zona/builder.py +++ b/src/zona/builder.py @@ -47,9 +47,7 @@ class ZonaBuilder: destination=destination, url=str(destination.relative_to(layout.output)), ) - if path.name.endswith( - ".md" - ) and not path.is_relative_to( + if path.name.endswith(".md") and not path.is_relative_to( layout.root / "content" / "static" ): logger.debug( @@ -72,13 +70,11 @@ class ZonaBuilder: item.copy = False name = destination.stem if name == "index": - item.destination = ( - item.destination.with_suffix(".html") + item.destination = item.destination.with_suffix( + ".html" ) else: - relative = path.relative_to(base).with_suffix( - "" - ) + relative = path.relative_to(base).with_suffix("") name = relative.stem item.destination = ( layout.output @@ -90,9 +86,7 @@ class ZonaBuilder: layout.output ) item.url = ( - "" - if rel_url == Path(".") - else rel_url.as_posix() + "" if rel_url == Path(".") else rel_url.as_posix() ) items.append(item) self.items = items @@ -118,9 +112,7 @@ class ZonaBuilder: # write code highlighting stylesheet if self.config.markdown.syntax_highlighting.enabled: pygments_style = zmd.get_style_defs(self.config) - pygments_path = ( - self.layout.output / "static" / "pygments.css" - ) + pygments_path = self.layout.output / "static" / "pygments.css" util.ensure_parents(pygments_path) pygments_path.write_text(pygments_style) for item in self.item_map.values(): @@ -137,6 +129,7 @@ class ZonaBuilder: source=item.source, layout=self.layout, item_map=self.item_map, + metadata=item.metadata, ) # TODO: test this rendered = templater.render_item(item, raw_html) diff --git a/src/zona/markdown.py b/src/zona/markdown.py index f41a45d..ce73016 100644 --- a/src/zona/markdown.py +++ b/src/zona/markdown.py @@ -31,6 +31,7 @@ from zona import util from zona.config import ZonaConfig from zona.layout import Layout from zona.log import get_logger +from zona.metadata import Metadata from zona.models import Item logger = get_logger() @@ -143,6 +144,7 @@ def md_to_html( source: Path | None = None, layout: Layout | None = None, item_map: dict[Path, Item] | None = None, + metadata: Metadata | None = None, ) -> str: extensions: Sequence[Any] = [ BetterEmExtension(), @@ -163,12 +165,13 @@ def md_to_html( SaneListExtension(), MarkdownInHtmlExtension(), EscapeAllExtension(hardbreak=True), - LaTeX2MathMLExtension(), ] kwargs: dict[str, Any] = { "extensions": extensions, "tab_length": 2, } + if metadata and metadata.math: + kwargs["extensions"].append(LaTeX2MathMLExtension()) if config: kwargs["extensions"].extend( [ diff --git a/src/zona/metadata.py b/src/zona/metadata.py index 63fc43f..b079266 100644 --- a/src/zona/metadata.py +++ b/src/zona/metadata.py @@ -24,6 +24,7 @@ class Metadata: template: str | None = None post: bool | None = None draft: bool = False + math: bool = True def parse_date(raw_date: str | date | object) -> date: