Remove fill and stroke attributes where their value was black
This commit is contained in:
@@ -80,6 +80,8 @@ final class IconExtension extends AbstractExtension
|
|||||||
throw new \TypeError('Size value must be an integer');
|
throw new \TypeError('Size value must be an integer');
|
||||||
|
|
||||||
$markup = $this->setSize($markup, $options['size']);
|
$markup = $this->setSize($markup, $options['size']);
|
||||||
|
$markup = $this->removeBlackStrokeAttributes($markup);
|
||||||
|
$markup = $this->removeBlackFillAttributes($markup);
|
||||||
|
|
||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
@@ -153,6 +155,16 @@ final class IconExtension extends AbstractExtension
|
|||||||
|
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function removeBlackStrokeAttributes(string $content): string
|
||||||
|
{
|
||||||
|
return preg_replace('/stroke="\s*(#0{6}|#000)|(rgb\(\s*0,\s*0,\s*0\s*\))|(black)\s*"/', '', $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function removeBlackFillAttributes(string $content): string
|
||||||
|
{
|
||||||
|
return preg_replace('/fill="\s*(#0{6}|#000)|(rgb\(\s*0,\s*0,\s*0\s*\))|(black)\s*"/', '', $content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IconNotFound extends \Exception {};
|
class IconNotFound extends \Exception {};
|
||||||
|
|||||||
@@ -194,4 +194,22 @@ class IconExtensionTest extends TestCase
|
|||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
new IconExtension(['/'], [['stroke' => '']]);
|
new IconExtension(['/'], [['stroke' => '']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBlackStrokeAttributeValuesAreRemoved(): void
|
||||||
|
{
|
||||||
|
$content = $this->icon->renderIcon(['icon' => self::ICON]);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/stroke="\s*#000\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/stroke="\s*#000000\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/stroke="\s*#black\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/stroke="\s*rgb\(0,\s*0,\s*0\)\s*"/', $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBlackFillAttributeValuesAreRemoved(): void
|
||||||
|
{
|
||||||
|
$content = $this->icon->renderIcon(['icon' => self::ICON]);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/fill="\s*#000\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/fill="\s*#000000\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/fill="\s*#black\s*"/', $content);
|
||||||
|
$this->assertDoesNotMatchRegularExpression('/fill="\s*rgb\(0,\s*0,\s*0\)\s*"/', $content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="96 96 320 320">
|
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="96 96 320 320">
|
||||||
<title>Some cross lol</title>
|
<title>Some cross lol</title>
|
||||||
|
<line fill="rgb(0, 0, 0)"></line>
|
||||||
|
<line fill="#000"></line>
|
||||||
|
<line fill="#000000"></line>
|
||||||
|
<line fill="black"></line>
|
||||||
<line x1="256" y1="112" x2="256" y2="400" width="101" height="101" style="fill: none; stroke: rgb(0,0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
<line x1="256" y1="112" x2="256" y2="400" width="101" height="101" style="fill: none; stroke: rgb(0,0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
||||||
<line x1="400" y1="256" x2="112" y2="256" width="102" height="102" style="fill: none; stroke: #000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
<line x1="400" y1="256" x2="112" y2="256" width="102" height="102" style="fill: none; stroke: #000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 498 B After Width: | Height: | Size: 631 B |
Reference in New Issue
Block a user