-
Notifications
You must be signed in to change notification settings - Fork 805
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
Customizer > Custom CSS: Add support for CSS variables #20129
Open
danieldudzic
wants to merge
6
commits into
trunk
Choose a base branch
from
add/custom-css-variable-support
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a18af1c
Customizer > Custom CSS: Add support for CSS variables
danieldudzic d61e021
Add unit tests for CSS Tidy
scruffian 2d19598
Add changelog entry
scruffian fdcc71b
Fix unit tests
scruffian d44b1d1
Merge branch 'master' into add/custom-css-variable-support
samiff 7480f8f
phpcs spacing
samiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-custom-css-variable-support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: compat | ||
|
||
Modified csstidy to allow css variable properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,7 @@ function __construct() { | |
$this->settings['discard_invalid_properties'] = false; | ||
$this->settings['css_level'] = 'CSS2.1'; | ||
$this->settings['preserve_css'] = false; | ||
$this->settings['preserve_css_variables'] = false; | ||
$this->settings['timestamp'] = false; | ||
$this->settings['template'] = ''; // say that propertie exist | ||
$this->set_cfg('template','default'); // call load_template | ||
|
@@ -1180,9 +1181,21 @@ function property_is_valid($property) { | |
$property = strtolower($property); | ||
if (in_array(trim($property), $GLOBALS['csstidy']['multiple_properties'])) $property = trim($property); | ||
$all_properties = & $GLOBALS['csstidy']['all_properties']; | ||
return (isset($all_properties[$property]) && strpos($all_properties[$property], strtoupper($this->get_cfg('css_level'))) !== false ); | ||
return ( ( isset( $all_properties[ $property ] ) && strpos( $all_properties[ $property ], strtoupper( $this->get_cfg( 'css_level' ) ) ) !== false ) || ( $this->get_cfg( 'preserve_css_variables' ) && $this->property_is_css_variable( $property ) ) ); | ||
} | ||
|
||
/** | ||
* Checks if a property is a css variable | ||
* Valid patterns must start with `--` and use alphanumeric characters optionally separated by `-`, `--`, or `_`. They must not end with a `-`, `--`, or `_`. | ||
* | ||
* @param string $property The property name to be checked. | ||
* @return bool; | ||
* @access public | ||
* @version 1.5 | ||
*/ | ||
public function property_is_css_variable( $property ) { | ||
return preg_match( '/^(--[a-zA-Z0-9]+)(([-]{1,2}|[_]?)[a-zA-Z0-9]+)*$/', $property ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI - I have modified the original regex: https://github.com/Automattic/jetpack/pull/19935/files#diff-09336221a25ca5f791ce459fbe1f11846ebd8ace76220d89eec08dca03591b70R1196 to allow for "nested" variables like, for example: |
||
} | ||
/** | ||
* Accepts a list of strings (e.g., the argument to format() in a @font-face src property) | ||
* and returns a list of the strings. Converts things like: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is really hard to grok, could we extract it to a function?