Skip to content

Style attribute processor#78

Draft
sirreal wants to merge 13 commits into
trunkfrom
css-token-style-attr-processor
Draft

Style attribute processor#78
sirreal wants to merge 13 commits into
trunkfrom
css-token-style-attr-processor

Conversation

@sirreal

@sirreal sirreal commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Depends on #92.

Adds WP_HTML_Style_Attribute_Processor, a forward-only processor for safely inspecting and mutating decoded CSS declaration lists from HTML style attributes.

This PR is stacked on the CSS token processor foundations in #92. That dependency provides WP_CSS_Token_Processor, WP_CSS_Builder, their test corpus, and focused unit tests. The reviewable change introduced here is the style-attribute processor, its specification, WordPress loading, and its tests. It does not include the earlier selector or select() API explorations.

Summary

  • Adds forward-only traversal over declarations while preserving duplicates.
  • Matches ordinary property names ASCII-case-insensitively and custom properties exactly.
  • Adds safe mutation through set_value(), set_important(), remove_declaration(), and append_declaration().
  • Preserves comments, invalid fragments, authored property spelling, and surrounding source when doing so is structurally safe.
  • Rejects malformed or declaration-breaking values atomically with false.
  • Repairs component values implicitly closed at EOF before appending, but only when the required closing delimiters can be determined precisely.
  • Documents the intended API and mutation guarantees in docs/wp-html-style-attribute-processor-spec.md.

API and scope

The processor accepts decoded style-attribute text, not raw HTML attribute syntax:

$styles = WP_HTML_Style_Attribute_Processor::create( $decoded_style );

while ( $styles->next_declaration( 'color' ) ) {
	$styles->set_value( 'green' );
}

$tags->set_attribute( 'style', $styles->get_updated_style() );

The initial API intentionally does not expose raw declaration values, bookmarks, cascade resolution, or property-specific browser grammar validation. It validates CSS declaration structure and safe placement rather than whether a particular property accepts a particular value.

Validation

Run on the combined branch based on current upstream/trunk:

  • WP_TESTS_SKIP_INSTALL=1 vendor/bin/phpunit tests/phpunit/tests/css-api/wpCssBuilder.php — 39 tests, 96 assertions
  • WP_TESTS_SKIP_INSTALL=1 vendor/bin/phpunit tests/phpunit/tests/css-api/wpCssTokenProcessor.php — 264 tests, 373 assertions
  • WP_TESTS_SKIP_INSTALL=1 vendor/bin/phpunit tests/phpunit/tests/html-api/wpHtmlStyleAttributeProcessor.php — 55 tests, 252 assertions
  • vendor/bin/phpcs --standard=phpcs.xml.dist on the six affected PHP source and test files
  • git diff --check

Trac ticket: https://core.trac.wordpress.org/ticket/62653

Use of AI Tools

AI assistance: Yes
Tool(s): ChatGPT/Codex
Model(s): GPT-5
Used for: extracting the CSS foundations into the dependent PR, refining the specification and implementation, adding tests, adversarial review, and updating this PR description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@sirreal
sirreal force-pushed the css-token-style-attr-processor branch from 1318192 to b458f80 Compare July 23, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants