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

✨ Support custom highlight color for text fragments in AMP documents #32591

Closed
wants to merge 9 commits into from

Conversation

dmanek
Copy link
Contributor

@dmanek dmanek commented Feb 10, 2021

Supports the following:

  1. valid CSS colors for color and background-color specified in ::target-text rule
  2. Invalid CSS color will not be applied (or overridden by default yellow color similar to the behavior in browsers)
  3. Defaults to yellow color if nothing is specified
  4. Applies the last style if multiple are specified

Does not support the following:

  1. Custom styles for different element eg. h1::target-text & p::target-text is not supported. The one specified last will be applied.

Fixes #32139.

@dmanek dmanek marked this pull request as ready for review February 11, 2021 18:55
for (let i = styles.length - 1; i >= 0; i--) {
const cssRules = styles[i]./*OK*/ innerHTML;
const targetTextRules = cssRules.match(
/::target-text\s*{\s*((.|\n)*?)\s*}/g
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this create a new regex object each time?

@@ -374,3 +374,17 @@ export function propagateObjectFitStyles(fromEl, toEl) {
function isVar(property) {
return property.startsWith('--');
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add quick description

}
const optionElement = new Option();
const {style} = optionElement;
style.color = color.replace('!important', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to strip whitespaces?

@dmanek dmanek closed this Jun 2, 2021
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.

Add support for Text Fragments in AMP
2 participants