Add <!-- %revision% --> template placeholder (port of upstream PR #492)

Adds a _get_latest_revision() helper that extracts the last entry from
metadata.revisions. Allows templates to show the current revision
indicator without rendering the full revision table.
This commit is contained in:
Ryan Malloy 2026-02-13 03:51:37 -07:00
parent 254be36948
commit 79be720eab
2 changed files with 8 additions and 0 deletions

View File

@ -40,6 +40,7 @@ Note that there must be one single space between `--` and `%` at both ends.
| `<!-- %sheet_total% -->` | `1` (multi-page documents not yet supported) | | `<!-- %sheet_total% -->` | `1` (multi-page documents not yet supported) |
| `<!-- %diagram% -->` | Embedded SVG diagram as valid HTML | | `<!-- %diagram% -->` | Embedded SVG diagram as valid HTML |
| `<!-- %diagram_png_b64% -->` | Embedded base64 encoded PNG diagram as URI | | `<!-- %diagram_png_b64% -->` | Embedded base64 encoded PNG diagram as URI |
| `<!-- %revision% -->` | The name of the last revision |
| `<!-- %{item}% -->` | String or numeric value of `metadata.{item}` | | `<!-- %{item}% -->` | String or numeric value of `metadata.{item}` |
| `<!-- %{item}_{i}% -->` | Category number `{i}` within dict value of `metadata.{item}` | | `<!-- %{item}_{i}% -->` | Category number `{i}` within dict value of `metadata.{item}` |
| `<!-- %{item}_{i}_{key}% -->` | Value of `metadata.{item}.{category}.{key}` | | `<!-- %{item}_{i}_{key}% -->` | Value of `metadata.{item}.{category}.{key}` |

View File

@ -64,6 +64,12 @@ def get_mime_subtype(filename: Union[str, Path]) -> str:
return mime_subtype return mime_subtype
def _get_latest_revision(metadata: Dict) -> str:
if "revisions" not in metadata:
return ""
return list(metadata.get("revisions"))[-1]
def embed_svg_images_file( def embed_svg_images_file(
filename_in: Union[str, Path], overwrite: bool = True filename_in: Union[str, Path], overwrite: bool = True
) -> None: ) -> None:
@ -152,6 +158,7 @@ def generate_html_output(
"<!-- %template_sheetsize% -->": metadata.get("template", {}).get( "<!-- %template_sheetsize% -->": metadata.get("template", {}).get(
"sheetsize", "" "sheetsize", ""
), ),
"<!-- %revision% -->": _get_latest_revision(metadata),
} }
def replacement_if_used(key: str, func: Callable[[], str]) -> None: def replacement_if_used(key: str, func: Callable[[], str]) -> None: