Skip to content

Introduce class modification helpers for block markup - #19

Open
kadamwhite wants to merge 2 commits into
mainfrom
class-methods
Open

Introduce class modification helpers for block markup#19
kadamwhite wants to merge 2 commits into
mainfrom
class-methods

Conversation

@kadamwhite

@kadamwhite kadamwhite commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Adds three new chaining methods to make it easier to update a class in both the block's HTML and the block's attributes simultaneously:

->add_class(
    pattern_slug: 'theme/hero',
    block_type:   'core/heading',
    occurrence:   0,
    classes:      'is-style-display'
)
->remove_class(
    'theme/hero',
    'core/paragraph',
    occurrence: 0,
    classes: 'is-style-lede'
)
->replace_class(
    pattern_slug: 'theme/hero',
    block_type:   'core/heading',
    occurrence:   0,
    old_classes:  'is-style-default',
    new_classes:  'is-style-display'
)

@kadamwhite kadamwhite changed the title WIP: Class modification API Introduce class modification helpers for block markup Sep 2, 2026
Comment thread docs/03-template-api.md
### `remove_class()`

```php
->remove_class( 'theme/hero', 'core/paragraph', occurrence: 0, classes: 'is-style-lede' )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->remove_class( 'theme/hero', 'core/paragraph', occurrence: 0, classes: 'is-style-lede' )
->remove_class(
pattern_slug: 'theme/hero',
block_type: 'core/paragraph',
occurrence: 0,
classes: 'is-style-lede'
)

I suppose we should be consistent in our docs style...?

@kadamwhite
kadamwhite marked this pull request as ready for review September 2, 2026 21:29
@kadamwhite

kadamwhite commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Things I'd like to add / fix : That situation where we can end up with <p > (whitespace left over from tag processor) probably breaks block validation, and I don't like that addClass and removeClass always execute in that order rather than respecting call order. It shouldn't matter logically but feels like it could somehow be an issue?

Edit: Confirmed the trailing whitespace is digested totally OK by simple-html-tokenizer, so no issue there.

@kadamwhite

Copy link
Copy Markdown
Contributor Author

Adjusted my other wishlist item. Ready for review!

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