Skip to content
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

fix: remove mark background in Newspack blocks #1363

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

laurelfulford
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This is a long explanation for a tiny code change:

Context: The RichText fields in Gutenberg allow some minor text formatting -- bold, italic, link, highlights (text and background colours). The highlights use the mark tag.

The mark tag typically has some standard styling in HTML (bright yellow by default in most browsers; kind of a mellow-er yellow in our theme).

In most cases, Gutenberg works around that by adding style="background-color: rgba(0, 0, 0, 0)" to mark tags that don't have a background colour.

Publishers have very occasionally been using the highlight option to change the section title of the Homepage Posts block, or the button text colour in the Donate block.

The issue: In both blocks, we're sanitizing the strings on the PHP side using wp_kses_post, which is stripping out rgba() (more info here). This causes the mark tag to display the yellow background. Though most Gutenberg blocks appear not to have this issue, the occasional one that uses wp_kses_post for sanitizing text -- like the search block's button -- display the same issue.

The fix: The work around here is kind of hacky, but quick: rather than trying to get rgba() allowed in the blocks, or rewriting the sanitization, I opted to override the mark background colour when the HTML tag is used in these blocks. This was added to the blocks rather than the theme because this would be an issue with any theme (unless that theme is overriding the browser default and removing the mark background).

I'm definitely open to feedback on this approach!

Closes #1285; see 1203695565716937-as-1203423790806450

How to test the changes in this Pull Request:

  1. Add a Homepage Posts block and give it a 'Section title'.
  2. Highlight some of the section title and using the caret dropdown in the block toolbar, select Highlight:

image

  1. Change the text colour.
  2. Repeat steps 1-3, but change the text background instead -- this is just to confirm this still works.
  3. Add a Donate block.
  4. Highlight some of the Donate Now button text, and give it a text colour.
  5. Highlight some of the Thank you text, and give it a text colour.
  6. Repeat steps 5-7, but instead of giving each section of text a background colour.
  7. Publish and view on the front-end.
  8. Note the light yellow highlight behind the text colour that was changed; your background colour should be applied as expected.

image

image

  1. Apply the PR and run npm run build.
  2. Confirm the light yellow highlight is gone from your text colour highlights without impacting your background colour highlights.

image

image

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Nice, simple fix for what seems like a pretty vexing issue. 👍

@laurelfulford
Copy link
Contributor Author

Thanks @dkoo! Yeah, I fell down a bit of a rabbit hole with this one... 😅

@laurelfulford laurelfulford merged commit 295b7d1 into master Feb 3, 2023
@laurelfulford laurelfulford deleted the fix/1285-highlight-text-background branch February 3, 2023 19:55
matticbot pushed a commit that referenced this pull request Feb 17, 2023
# [1.63.0-alpha.1](v1.62.0...v1.63.0-alpha.1) (2023-02-17)

### Bug Fixes

* attribute types for custom author fields ([#1365](#1365)) ([483e49c](483e49c))
* remove mark background in Newspack blocks ([#1363](#1363)) ([295b7d1](295b7d1))

### Features

* **donate-block:** native wc subs ([#1359](#1359)) ([9834aa0](9834aa0))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.63.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 28, 2023
# [1.63.0](v1.62.0...v1.63.0) (2023-02-28)

### Bug Fixes

* attribute types for custom author fields ([#1365](#1365)) ([483e49c](483e49c))
* remove mark background in Newspack blocks ([#1363](#1363)) ([295b7d1](295b7d1))

### Features

* **donate-block:** native wc subs ([#1359](#1359)) ([9834aa0](9834aa0))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.63.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Donate Block: Highlight text styles on button add yellow background
3 participants