Skip to content

Commit 478605d

Browse files
committed
Add support for ::highlight
1 parent 496f4f6 commit 478605d

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

scripts/build-prefixes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ let mdnFeatures = {
288288
oklabColors: mdn.css.types.color.oklab.__compat.support,
289289
colorFunction: mdn.css.types.color.color.__compat.support,
290290
spaceSeparatedColorNotation: mdn.css.types.color.rgb.space_separated_parameters.__compat.support,
291+
highlight: mdn.css.selectors.highlight.__compat.support,
291292
textDecorationThicknessPercent: mdn.css.properties['text-decoration-thickness'].percentage.__compat.support,
292293
textDecorationThicknessShorthand: mdn.css.properties['text-decoration'].includes_thickness.__compat.support,
293294
cue: mdn.css.selectors.cue.__compat.support,

selectors/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,6 +3933,10 @@ pub mod tests {
39333933
assert!(parse("foo::details-content").is_ok());
39343934
assert!(parse("foo::target-text").is_ok());
39353935

3936+
assert!(parse("::highlight").is_err());
3937+
assert!(parse("::highlight()").is_err());
3938+
assert!(parse("::highlight(custom-highlight-name)").is_ok());
3939+
39363940
assert!(parse("select::picker").is_err());
39373941
assert!(parse("::picker()").is_err());
39383942
assert!(parse("::picker(select)").is_ok());

src/compat.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub enum Feature {
9292
HasSelector,
9393
HebrewListStyleType,
9494
HexAlphaColors,
95+
Highlight,
9596
HiraganaIrohaListStyleType,
9697
HiraganaListStyleType,
9798
HypotFunction,
@@ -2448,6 +2449,46 @@ impl Feature {
24482449
return false;
24492450
}
24502451
}
2452+
Feature::Highlight => {
2453+
if let Some(version) = browsers.chrome {
2454+
if version < 6881280 {
2455+
return false;
2456+
}
2457+
}
2458+
if let Some(version) = browsers.edge {
2459+
if version < 6881280 {
2460+
return false;
2461+
}
2462+
}
2463+
if let Some(version) = browsers.opera {
2464+
if version < 4718592 {
2465+
return false;
2466+
}
2467+
}
2468+
if let Some(version) = browsers.safari {
2469+
if version < 1114624 {
2470+
return false;
2471+
}
2472+
}
2473+
if let Some(version) = browsers.ios_saf {
2474+
if version < 1114624 {
2475+
return false;
2476+
}
2477+
}
2478+
if let Some(version) = browsers.samsung {
2479+
if version < 1310720 {
2480+
return false;
2481+
}
2482+
}
2483+
if let Some(version) = browsers.android {
2484+
if version < 6881280 {
2485+
return false;
2486+
}
2487+
}
2488+
if browsers.firefox.is_some() || browsers.ie.is_some() {
2489+
return false;
2490+
}
2491+
}
24512492
Feature::TextDecorationThicknessPercent => {
24522493
if let Some(version) = browsers.chrome {
24532494
if version < 5701632 {

src/selector.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ pub enum PseudoElement<'i> {
903903
/// The [::placeholder](https://drafts.csswg.org/css-pseudo-4/#placeholder-pseudo) pseudo element.
904904
#[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
905905
Placeholder(VendorPrefix),
906+
/// The [::highlight()](https://drafts.csswg.org/css-highlight-api/#custom-highlight-pseudo) functional pseudo element.
907+
HighlightFunction {
908+
/// A custom highlight name.
909+
name: CustomIdent<'i>,
910+
},
906911
/// The [::marker](https://drafts.csswg.org/css-pseudo-4/#marker-pseudo) pseudo element.
907912
Marker,
908913
/// The [::backdrop](https://fullscreen.spec.whatwg.org/#::backdrop-pseudo-element) pseudo element.
@@ -1160,6 +1165,11 @@ where
11601165
FirstLetter => dest.write_str(":first-letter"),
11611166
DetailsContent => dest.write_str("::details-content"),
11621167
TargetText => dest.write_str("::target-text"),
1168+
HighlightFunction { name } => {
1169+
dest.write_str("::highlight(")?;
1170+
name.to_css(dest)?;
1171+
dest.write_char(')')
1172+
}
11631173
Marker => dest.write_str("::marker"),
11641174
Selection(prefix) => write_prefixed!(prefix, "selection"),
11651175
Cue => dest.write_str("::cue"),
@@ -1935,6 +1945,7 @@ pub(crate) fn is_compatible(selectors: &[Selector], targets: Targets) -> bool {
19351945
PseudoElement::TargetText => Feature::TargetText,
19361946
PseudoElement::Selection(prefix) if *prefix == VendorPrefix::None => Feature::Selection,
19371947
PseudoElement::Placeholder(prefix) if *prefix == VendorPrefix::None => Feature::Placeholder,
1948+
PseudoElement::HighlightFunction { name: _ } => Feature::Highlight,
19381949
PseudoElement::Marker => Feature::MarkerPseudo,
19391950
PseudoElement::Backdrop(prefix) if *prefix == VendorPrefix::None => Feature::Dialog,
19401951
PseudoElement::Cue => Feature::Cue,

0 commit comments

Comments
 (0)