fix: remove mark background in Newspack blocks #1363
Merged
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.
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)"
tomark
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 outrgba()
(more info here). This causes themark
tag to display the yellow background. Though most Gutenberg blocks appear not to have this issue, the occasional one that useswp_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 themark
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 themark
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:
npm run build
.Other information: