@@ -28,10 +28,10 @@ public override string ToString()
2828
2929 public string SerializeCss ( string hashId , List < ( string , string ) > effects = null )
3030 {
31- return Serialize ( Compile ( ParseStyle ( true , hashId , effects ) ) , Stringify ) ;
31+ return Serialize ( Compile ( ParseStyle ( true , false , hashId , effects ) ) , Stringify ) ;
3232 }
3333
34- internal string ParseStyle ( bool root , string hashId , List < ( string , string ) > effects = null )
34+ internal string ParseStyle ( bool root , bool injectHash , string hashId , List < ( string , string ) > effects = null )
3535 {
3636 var sb = new StringBuilder ( ) ;
3737
@@ -54,20 +54,28 @@ internal string ParseStyle(bool root, string hashId, List<(string, string)> effe
5454 // sub style sheet
5555 foreach ( var subStyle in _styles )
5656 {
57- var mergedKey = subStyle . Key . Trim ( ) ;
58- var nextRoot = false ;
59- if ( mergedKey . StartsWith ( "@" ) )
57+ var subInjectHash = false ;
58+ var nextRoot = false ;
59+ var mergedKey = subStyle . Key . Trim ( ) ;
60+
61+ if ( ( root || injectHash ) && ! string . IsNullOrEmpty ( hashId ) )
62+ {
63+ if ( mergedKey . StartsWith ( "@" ) )
64+ {
65+ subInjectHash = true ;
66+ }
67+ else
68+ {
69+ mergedKey = InjectSelectorHash ( mergedKey , hashId ) ;
70+ }
71+ }
72+ else if ( root && string . IsNullOrEmpty ( hashId ) && ( mergedKey == "&" || mergedKey == "" ) )
6073 {
61- // if is media type, skip and insert hashId from subStyle.
62- root = false ;
74+ mergedKey = "" ;
6375 nextRoot = true ;
6476 }
6577
66- if ( root && ! string . IsNullOrEmpty ( hashId ) )
67- {
68- mergedKey = InjectSelectorHash ( mergedKey , hashId ) ;
69- }
70- sb . Append ( $ "{ mergedKey } {{{subStyle.Value.ParseStyle(nextRoot, hashId, effects)}}}") ;
78+ sb . Append ( $ "{ mergedKey } {{{subStyle.Value.ParseStyle(nextRoot, subInjectHash, hashId, effects)}}}") ;
7179 }
7280
7381 return sb . ToString ( ) ;
0 commit comments