Add HybridTag base class and BlockBody reparenting#2059
Open
charlespwd wants to merge 1 commit intomainfrom
Open
Add HybridTag base class and BlockBody reparenting#2059charlespwd wants to merge 1 commit intomainfrom
charlespwd wants to merge 1 commit intomainfrom
Conversation
charlespwd
commented
Mar 19, 2026
e7d47ed to
f39e154
Compare
charlespwd
commented
Mar 19, 2026
de02dd6 to
dae47e3
Compare
dae47e3 to
28b0cc2
Compare
Introduces hybrid tags — tags that work in both self-closing and block form. When BlockBody#parse encounters an end tag for a registered hybrid tag, it walks backward through sibling nodes and reparents them into the tag's body. No tokenizer changes needed. - HybridTag subclasses must implement blank? (raises NotImplementedError) - Block form is derived from @Body presence, no separate tracking flag - Nested hybrid tags in block form are detected during the backward walk - Parent BlockBody blank state is not recomputed since hybrid tags that render content already return blank? == false Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
28b0cc2 to
cca902b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds foundational support for "hybrid tags" — tags that can function in both self-closing form (
{% section 'name' %}) and block form ({% section 'name' %}...{% endsection %}).Changes
Liquid::HybridTag— New base class extendingLiquid::Blockthat supports two rendering modes:render_self_closing_to_output_bufferrender_block_form_to_output_bufferendsection)BlockBody#parsereparenting — When the parser encounters an end tag for a registered hybrid tag (e.g.,{% endsection %}), it looks back through@nodelist, finds the matching hybrid tag, splices intervening nodes into its body, and flips it to block form. No tokenizer changes needed.Parse-time nesting prevention — Hybrid tags of the same type cannot be nested (raises
SyntaxError). Sequential hybrid tags and different types are allowed.@blankrecomputation — After reparenting, the parentBlockBodyrecomputes its@blankflag based on remaining nodes.Design
Uses end-tag-triggered reparenting rather than tokenizer lookahead. When
BlockBody#parseencounters{% endsection %}:@nodelistbackwards to find the matchingsectiontagreparent_as_block(spliced_nodes)on the hybrid tag@blankfor the parent bodyThis approach requires zero tokenizer modifications.
Test plan
@blankrecomputation after reparenting🤖 Generated with Claude Code