Skip to content

Commit

Permalink
Process CSS nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Dec 20, 2022
1 parent e36ebbf commit 16a7720
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,18 +939,30 @@ export function useGlobalStylesOutput() {
},
];

const processCSSNesting = ( css, blockSelector ) => {
let processedCSS = '';

// Split CSS nested rules.
const parts = css.split( '&' );
parts.forEach( ( part ) => {
processedCSS += ! part.includes( '{' )
? blockSelector + '{' + part + '}' // If the part doesn't contain braces, it applies to the root level.
: blockSelector + part; // Prepend the selector, which effectively replaces the "&" character.
} );
return processedCSS;
};

// Loop through the blocks to check if there are custom CSS values.
// If there are, get the block selector and push the selector together with
// the CSS value to the 'stylesheets' array.
Object.entries( blockNames ).forEach( ( name ) => {
if ( mergedConfig.styles.blocks[ name[ 0 ] ]?.css ) {
const selector = blockSelectors[ name[ 0 ] ].selector;
stylesheets.push( {
css:
selector +
'{' +
mergedConfig.styles.blocks[ name[ 0 ] ]?.css +
'}',
css: processCSSNesting(
mergedConfig.styles.blocks[ name[ 0 ] ]?.css,
selector
),
isGlobalStyles: true,
} );
}
Expand Down

1 comment on commit 16a7720

@github-actions
Copy link

@github-actions github-actions bot commented on 16a7720 Dec 20, 2022

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3738691478
📝 Reported issues:

Please sign in to comment.