Skip to content

Tags: add BaseTag.from_jinja() to convert Jinja output into real Air Tags via from_html #1015

@pygarap

Description

@pygarap

Summary

Add a strict BaseTag.from_jinja() helper that renders a Jinja template to HTML and immediately converts it into real Air Tags nodes via BaseTag.from_html.

This should be strict-only: invalid HTML must raise, matching BaseTag.from_html behavior.

Motivation

Mixing Air Tags and Jinja is a valid use case, but embedding rendered Jinja output as a raw HTML string (SafeStr / trusted HTML) inside an Air Tags tree makes that subtree opaque to anything that expects real tags (tree transforms, structure-based features, future tooling, etc.).

We already have a non-strict path that returns template output as a string for insertion into tags. That was implemented in PR #981 and closed issue #231. This request is specifically for the strict option that converts template output into actual Air Tags nodes.

Proposed API

BaseTag.from_jinja(template, /, **context) -> BaseTag

Behavior:

  1. Render the Jinja template to an HTML string.
  2. Parse using BaseTag.from_html(rendered_html).
  3. Return the resulting Air Tags tree.

Notes:

  • No non-strict mode here. If parsing fails, raise (same as BaseTag.from_html).

References

Acceptance criteria

  • BaseTag.from_jinja() exists and is documented.
  • Tests cover:
    • valid fragment output
    • full document output
    • invalid HTML raises (no fallback)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions