-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Style engine: prettify output #42909
Conversation
Turning off prettify by default.
Add defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) to style engine to determine prettifier
Nice one, this is going to make debugging style output quite a bit easier! |
Thanks for working on this; does this require use of wp-env to since it's relying on prettier ? |
👋 Do you mean prettier, the formatter? The formatting options in the style engine, are completely independent and require no library. Ultimately, it's formatting the CSS output with spaces, tabs and new lines to make it a bit more readable during development. If you're not using wp-env to develop, you can set the PHP global constant Now that you've brought it up, it might be a good idea to introduce some sort of filter/toggle. I'll make a note. Thank you! |
What?
Introducing prettify to making debugging a little easier.
❗❗❗ Note! Prettify must be turned on. We remove spaces and new lines by default.
Prettify is supported for CSS rules and CSS declarations.
An
$indent_count
parameter is also available in case we ever want to print nested CSS layers or rules.Why?
Gutenberg uses
defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG
in various place to control the styles output.This gives developers the option to see prettified CSS during development for ease of debugging.
So, from this:
To this:
How?
WP_Style_Engine_Processor->get_css( array( 'prettify'=> true ) );
// add new lines, a single indent and spaces.WP_Style_Engine_CSS_Rule->get_css( true, 2 );
// prettify with an indent of 2 tabsWP_Style_Engine_CSS_Declarations->get_declarations_string( true );
// prettify declarations (add spaces)Testing Instructions
Unit tests
npm run test-unit-php
Manual
Run this branch using
npm run wp-env start
Check that the pretty styles are output in the dev environment (http://localhost:8888/)
Disable prettify manually in order to see the minified CSS if you're working in a dev environment:
Check the source of your test page. 🚀