"""Render a template's Markdown skeleton and title into a new draft document.""" from datetime import UTC, datetime from app.authoring.schema import AuthoringTemplate from app.models import User def render_title(template: AuthoringTemplate, user: User) -> str: today = datetime.now(UTC).date().isoformat() return ( template.title_template.replace("{{user.name}}", user.name) .replace("{{date}}", today) .strip() ) def render_skeleton(template: AuthoringTemplate) -> str: """The Markdown the editor opens with: the skeleton verbatim, normalized to a single trailing newline. An empty skeleton yields an empty document the author fills from scratch.""" skeleton = template.skeleton.strip() return f"{skeleton}\n" if skeleton else ""