@@ -40,23 +40,43 @@ foreach ($file in $svgFiles) {
4040 }
4141
4242 # All rect elements with an opacity attribute should get fill="currentColor"
43- $pathElements = $svgXml.GetElementsByTagName (" rect" )
44- foreach ($path in $pathElements ) {
45- if ($path .HasAttribute (" opacity" ) -and -not $path .HasAttribute (" fill" )) {
46- $path .SetAttribute (" fill" , " currentColor" )
43+ $rectElements = $svgXml.GetElementsByTagName (" rect" )
44+ foreach ($rect in $rectElements ) {
45+ if ($rect .HasAttribute (" opacity" ) -and -not $rect .HasAttribute (" fill" )) {
46+ $rect .SetAttribute (" fill" , " currentColor" )
4747 Write-Host " Added <rect ... fill=`" currentColor`" > in: $ ( $file.FullName ) "
4848 }
4949 }
5050
5151 # All polygon elements with an opacity attribute should get fill="currentColor"
52- $pathElements = $svgXml.GetElementsByTagName (" polygon" )
53- foreach ($path in $pathElements ) {
54- if ($path .HasAttribute (" opacity" ) -and -not $path .HasAttribute (" fill" )) {
55- $path .SetAttribute (" fill" , " currentColor" )
52+ $polygonElements = $svgXml.GetElementsByTagName (" polygon" )
53+ foreach ($polygon in $polygonElements ) {
54+ if ($polygon .HasAttribute (" opacity" ) -and -not $polygon .HasAttribute (" fill" )) {
55+ $polygon .SetAttribute (" fill" , " currentColor" )
5656 Write-Host " Added <polygon ... fill=`" currentColor`" > in: $ ( $file.FullName ) "
5757 }
5858 }
5959
60+ # For any file where the name ends with -fill.svg...
61+ if ($file.Name -like " *-fill.svg" ) {
62+ # ... ensure all path elements have fill="currentColor"
63+ $pathElements = $svgXml.GetElementsByTagName (" path" )
64+ foreach ($path in $pathElements ) {
65+ if (-not $path.HasAttribute (" fill" )) {
66+ $path.SetAttribute (" fill" , " currentColor" )
67+ Write-Host " Added <path ... fill=`" currentColor`" > in: $ ( $file.FullName ) "
68+ }
69+ }
70+ # ensure rect elements have fill="currentColor"
71+ $rectElements = $svgXml.GetElementsByTagName (" rect" )
72+ foreach ($rect in $rectElements ) {
73+ if (-not $rect.HasAttribute (" fill" )) {
74+ $rect.SetAttribute (" fill" , " currentColor" )
75+ Write-Host " Added <rect ... fill=`" currentColor`" > in: $ ( $file.FullName ) "
76+ }
77+ }
78+ }
79+
6080 $svgXml.Save ($file.FullName )
6181 Write-Host " Updated file: $ ( $file.FullName ) "
6282}
0 commit comments