@@ -434,19 +434,6 @@ export default async function getCSS({
434434 return colors . map ( ( { name} ) => name ) . join ( '\n' ) ;
435435 }
436436
437- // Merge shared variables into every color theme
438- for ( const declarations of shared ) {
439- for ( const declaration of declarations ) {
440- const { property, value} = declaration ;
441- for ( const theme of colors ) {
442- if ( ! ( property in theme ) ) {
443- theme [ property ] = value ;
444- theme . unshift ( declaration ) ;
445- }
446- }
447- }
448- }
449-
450437 rules = reverseUnique ( rules , rule => {
451438 const selector = rule . selectors . join ( ',' ) ;
452439 const body = rule . declarations . map ( ( { property, value} ) => `${ property } : ${ value } ` ) . join ( ';' ) ;
@@ -481,6 +468,8 @@ export default async function getCSS({
481468 }
482469
483470 if ( ! onlyStyles ) {
471+ const sharedDeclarations = filterColors ( shared . flat ( 1 ) , usedVariables ) ;
472+
484473 if ( light === dark ) {
485474 if ( preserveVariables ) {
486475 rules . unshift ( {
@@ -493,9 +482,18 @@ export default async function getCSS({
493482 ...filterColors ( colors [ light ] , usedVariables ) ,
494483 ] ,
495484 } ) ;
485+
486+ rules . unshift ( {
487+ type : 'rule' ,
488+ selectors : [ '.markdown-body' ] ,
489+ declarations : sharedDeclarations ,
490+ } ) ;
496491 } else {
497492 rules = applyColors ( colors [ light ] , rules ) ;
498493
494+ const sharedColors = Object . fromEntries ( sharedDeclarations . map ( ( { property, value} ) => [ property , value ] ) ) ;
495+ rules = applyColors ( sharedColors , rules ) ;
496+
499497 if ( light . startsWith ( 'dark' ) ) {
500498 rules [ 0 ] . declarations . unshift ( colorSchemeDark ) ;
501499 }
@@ -530,6 +528,12 @@ export default async function getCSS({
530528 ] ,
531529 } ] ,
532530 } ) ;
531+
532+ rules . unshift ( {
533+ type : 'rule' ,
534+ selectors : [ '.markdown-body' ] ,
535+ declarations : sharedDeclarations ,
536+ } ) ;
533537 }
534538 }
535539
0 commit comments