Skip to content

CSS API: Add a text form of the comma-separated list split - #109

Open
sirreal wants to merge 2 commits into
css-api/css-token-processor-foundationsfrom
css-api/comma-separated-list-text
Open

sirreal wants to merge 2 commits into
css-api/css-token-processor-foundationsfrom
css-api/comma-separated-list-text

Conversation

@sirreal

@sirreal sirreal commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Caution

This is a work in progress draft and is not ready for any serious review.

Add WP_CSS_Token_Processor::split_comma_separated_list( $css ), which returns the source text between top-level commas. A comma inside a string, comment, escape, url token, function, (), [] or {} block stays in its item. Joining the items with commas reproduces the input.

Selector lists are comma-separated, and their callers in core prepend or append text to each selector as written, so they need text rather than tokens. Core splits them with explode( ',' ) or with scanners that track some of the cases above:

Input explode( ',' ) split_comma_separated_list()
[title="a,b"], c [title="a, b"], c [title="a,b"], c
:is(a, b) img, c :is(a, b) img, c :is(a, b) img, c

The method tokenizes the whole input. It follows the CSS Syntax 3 algorithm with one difference: a comma at the end of the input produces a final empty item, because the selector grammar rejects a trailing comma and the algorithm's result does not show one.

#98 adds the token form of the same split, parse_comma_separated_list(). The selector-list alternative, #102, uses this method.

Depends on WordPress#14781.

Trac ticket: TBD

Use of AI Tools

AI assistance: Yes
Tools: Claude Code
Models: Claude Opus 5.5
Used for: implementation, tests and this description.


This pull request is for code review only. Keep other discussion in the Trac ticket. Do not merge. See GitHub Pull Requests for Code Review in the Core Handbook.

Selector lists in theme.json, block supports, duotone and the style
engine are split with explode( ',' ) or with scanners that track some
nesting, which split inside strings, escapes, comments or blocks. Their
callers need the source text of each selector, as written, to prepend
or append to it.

The method returns the source text between top-level commas, found by
tokenizing the input. Joining the items with commas reproduces the
input. A comma at the end of the input produces a final empty item, as
the selector grammar rejects a trailing comma and the CSS Syntax 3
algorithm does not show one.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

1 participant