Templates + Markdown¶
Engrave renders Jinja2 templates discovered under your source directory. Use standard Jinja features plus a built-in Markdown helper/filter.
Rendering rules¶
- Only
.htmlfiles are rendered. A template is skipped if any path segment starts with_(e.g.,_partials/header.html), but it can still be included by other templates. - The relative path under
DIR_SRCis preserved inDIR_DEST(e.g.,pages/about/index.htmlstays nested). - Jinja loads templates relative to
DIR_SRC(or a list of template roots if you pass more than one), so{% extends "base.html" %}or{% include "partials/nav.html" %}work as usual.
Bringing in Markdown files¶
Use the global markdown() helper inside templates to load and render a Markdown file relative to the current template.
Details:
- Markdown files are rendered as Jinja templates first (using the current context), then converted to HTML, so you can use template variables in your .md snippets.
- Paths must be relative to the template; absolute paths raise an error and attempts to escape outside the configured loader roots are blocked.
- Lookups walk the loader search paths (handy when you pass multiple template roots) and fall back with a FileNotFoundError if the file is missing.
- File reads and compilation are cached per modification time, but Markdown content is re-rendered for each request so context changes are reflected.
Inline Markdown filter¶
Convert inline strings to HTML with the markdown filter. Results are cached with an LRU to avoid repeated parsing.
Organizing partials and assets¶
- Keep non-page templates under
_partials/or any_-prefixed folder to prevent standalone rendering (copy rules still apply to those paths). - Store reusable Markdown snippets in
includes/(or any folder) and pull them into pages withmarkdown(). - Pair your templates with asset copy rules (
--copy '.*\\.(css|js|svg)$') so builds place files alongside rendered HTML.