forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
HTML Templating #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sirreal
wants to merge
66
commits into
trunk
Choose a base branch
from
html-api/add-html-templating
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
HTML Templating #23
+1,907
−1
Conversation
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
54d85bc to
d90142b
Compare
Replace `extends WP_HTML_Tag_Processor` with an internal anonymous class that provides accessor methods for the protected properties needed during template rendering. This improves encapsulation by not exposing the tag processor's public API on the template class.
Add $compiled property and get_placeholders() accessor. The compile() method is stubbed and will be implemented to extract placeholder positions, lengths, and contexts from the template.
Parse funky comments (</%name>) to extract text placeholders. Store each placeholder's offsets (start position and length) and context. Repeated placeholders are captured as multiple offset entries.
Extract placeholders from attribute values using regex. When a placeholder appears in both text and attribute contexts, promote to attribute context (more restrictive escaping applies everywhere).
Trigger _doing_it_wrong() for: - Missing replacement keys (placeholder without value) - Unused replacement keys (value without placeholder) - Template values in attribute context Share compiled data between original and bound template instances for efficiency.
…plate Preparation for unifying $compiled, $text_normalizations, and $attr_escapes into a single edits array with a separate placeholder name index. See docs/plans/2026-02-06-unified-edits-array-design.md
Text normalizations are now appended to the unified edits array as pre-computed replacements. The legacy $text_normalizations array is retained temporarily for parallel validation during migration.
Text placeholders are now appended to the unified edits array with context='text'. Placeholder names are also registered in $placeholder_names for O(1) validation during bind().
Static text segments in attribute values are now decoded and re-encoded during compilation. Only segments that actually change are added to $edits. This moves escape computation from render time to compile time. Also fixes a typo in test_attribute_replacement_is_not_recursive where the placeholder syntax used `<%/` instead of the correct `</%`.
Attribute placeholders are now appended to the unified edits array with context='attribute'. Names are registered in $placeholder_names.
Render now iterates the edits array in reverse order instead of building an intermediate $updates array from three separate sources. Pre-computed replacements are applied directly; placeholders are looked up and escaped. Removes usort() call - edits are naturally in document order from compile. Also ensures bind() copies $edits and $placeholder_names to the new instance.
Validation now uses the pre-built $placeholder_names index for O(1) lookups instead of iterating through $compiled to build a lookup on each bind() call.
These are now fully superseded by the unified $edits array. Text normalizations and attribute escapes are stored as pre-computed replacements in $edits during compile().
Document that $compiled could be derived from $edits on-demand to eliminate redundant storage, but keeping it for now to preserve get_placeholders() API.
Apply WordPress Coding Standards formatting: - Align equals signs in assignment blocks - Format multi-line function calls (strtr) per PEAR standard
Replace the $compiled property with an $is_compiled boolean flag. The grouped placeholder metadata is now derived on-demand in get_placeholders() by iterating through the $edits array, eliminating redundant storage while maintaining identical public API behavior.
dee6179 to
03e6104
Compare
Converts test_escapes_static_text_around_placeholder_in_attribute from inline multiple assertions to a @dataProvider pattern for better test isolation and clearer failure messages.
Verify that render() returns false when replacements are: - integers - arrays - objects (without __toString) - null - booleans Only strings and WP_HTML_Template instances are valid replacement values. See #60229.
Implements ticket #60229 requirement for boolean attributes: - `true` converts `disabled="</%d>"` to `disabled` (boolean form) - `false` or `null` removes the attribute entirely - Only works when placeholder is the entire attribute value - Partial placeholders with boolean values return false
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.
WIP