added math frontmatter option

This commit is contained in:
Daniel Fichtinger 2025-07-06 21:09:55 -04:00
parent eacaeba2ab
commit 3037aa88d8
3 changed files with 12 additions and 15 deletions

View file

@ -47,9 +47,7 @@ class ZonaBuilder:
destination=destination, destination=destination,
url=str(destination.relative_to(layout.output)), url=str(destination.relative_to(layout.output)),
) )
if path.name.endswith( if path.name.endswith(".md") and not path.is_relative_to(
".md"
) and not path.is_relative_to(
layout.root / "content" / "static" layout.root / "content" / "static"
): ):
logger.debug( logger.debug(
@ -72,13 +70,11 @@ class ZonaBuilder:
item.copy = False item.copy = False
name = destination.stem name = destination.stem
if name == "index": if name == "index":
item.destination = ( item.destination = item.destination.with_suffix(
item.destination.with_suffix(".html") ".html"
) )
else: else:
relative = path.relative_to(base).with_suffix( relative = path.relative_to(base).with_suffix("")
""
)
name = relative.stem name = relative.stem
item.destination = ( item.destination = (
layout.output layout.output
@ -90,9 +86,7 @@ class ZonaBuilder:
layout.output layout.output
) )
item.url = ( item.url = (
"" "" if rel_url == Path(".") else rel_url.as_posix()
if rel_url == Path(".")
else rel_url.as_posix()
) )
items.append(item) items.append(item)
self.items = items self.items = items
@ -118,9 +112,7 @@ class ZonaBuilder:
# write code highlighting stylesheet # write code highlighting stylesheet
if self.config.markdown.syntax_highlighting.enabled: if self.config.markdown.syntax_highlighting.enabled:
pygments_style = zmd.get_style_defs(self.config) pygments_style = zmd.get_style_defs(self.config)
pygments_path = ( pygments_path = self.layout.output / "static" / "pygments.css"
self.layout.output / "static" / "pygments.css"
)
util.ensure_parents(pygments_path) util.ensure_parents(pygments_path)
pygments_path.write_text(pygments_style) pygments_path.write_text(pygments_style)
for item in self.item_map.values(): for item in self.item_map.values():
@ -137,6 +129,7 @@ class ZonaBuilder:
source=item.source, source=item.source,
layout=self.layout, layout=self.layout,
item_map=self.item_map, item_map=self.item_map,
metadata=item.metadata,
) )
# TODO: test this # TODO: test this
rendered = templater.render_item(item, raw_html) rendered = templater.render_item(item, raw_html)

View file

@ -31,6 +31,7 @@ from zona import util
from zona.config import ZonaConfig from zona.config import ZonaConfig
from zona.layout import Layout from zona.layout import Layout
from zona.log import get_logger from zona.log import get_logger
from zona.metadata import Metadata
from zona.models import Item from zona.models import Item
logger = get_logger() logger = get_logger()
@ -143,6 +144,7 @@ def md_to_html(
source: Path | None = None, source: Path | None = None,
layout: Layout | None = None, layout: Layout | None = None,
item_map: dict[Path, Item] | None = None, item_map: dict[Path, Item] | None = None,
metadata: Metadata | None = None,
) -> str: ) -> str:
extensions: Sequence[Any] = [ extensions: Sequence[Any] = [
BetterEmExtension(), BetterEmExtension(),
@ -163,12 +165,13 @@ def md_to_html(
SaneListExtension(), SaneListExtension(),
MarkdownInHtmlExtension(), MarkdownInHtmlExtension(),
EscapeAllExtension(hardbreak=True), EscapeAllExtension(hardbreak=True),
LaTeX2MathMLExtension(),
] ]
kwargs: dict[str, Any] = { kwargs: dict[str, Any] = {
"extensions": extensions, "extensions": extensions,
"tab_length": 2, "tab_length": 2,
} }
if metadata and metadata.math:
kwargs["extensions"].append(LaTeX2MathMLExtension())
if config: if config:
kwargs["extensions"].extend( kwargs["extensions"].extend(
[ [

View file

@ -24,6 +24,7 @@ class Metadata:
template: str | None = None template: str | None = None
post: bool | None = None post: bool | None = None
draft: bool = False draft: bool = False
math: bool = True
def parse_date(raw_date: str | date | object) -> date: def parse_date(raw_date: str | date | object) -> date: