From 3253a81d07cd01afcb651e309900d8ad58a052da Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Thu, 9 Jun 2016 21:35:53 +0200 Subject: [PATCH] Shorten colors some more if their color name is shorter As suggested on issue #109 --- src/CSS.php | 33 ++++++++++++++++++++++++++++++++- tests/css/CSSTest.php | 8 ++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/CSS.php b/src/CSS.php index 726dd0e..41f9564 100644 --- a/src/CSS.php +++ b/src/CSS.php @@ -487,7 +487,38 @@ protected function shortenHex($content) { $content = preg_replace('/(? 'azure', + '#F5F5DC' => 'beige', + '#A52A2A' => 'brown', + '#FF7F50' => 'coral', + '#FFD700' => 'gold', + '#808080' => 'gray', + '#008000' => 'green', + '#4B0082' => 'indigo', + '#FFFFF0' => 'ivory', + '#F0E68C' => 'khaki', + '#FAF0E6' => 'linen', + '#800000' => 'maroon', + '#000080' => 'navy', + '#808000' => 'olive', + '#CD853F' => 'peru', + '#FFC0CB' => 'pink', + '#DDA0DD' => 'plum', + '#800080' => 'purple', + '#F00' => 'red', + '#FA8072' => 'salmon', + '#A0522D' => 'sienna', + '#C0C0C0' => 'silver', + '#FFFAFA' => 'snow', + '#D2B48C' => 'tan', + '#FF6347' => 'tomato', + '#EE82EE' => 'violet', + '#F5DEB3' => 'wheat', + ); + + return str_ireplace(array_keys($colors), $colors, $content); } /** diff --git a/tests/css/CSSTest.php b/tests/css/CSSTest.php index b7af322..9f5e5b8 100644 --- a/tests/css/CSSTest.php +++ b/tests/css/CSSTest.php @@ -434,6 +434,14 @@ public function dataProvider() }', 'p{font-weight:400}', ); + $tests[] = array( + 'p{background-color:#ff0000}', + 'p{background-color:red}', + ); + $tests[] = array( + 'p{color:#F0E68C}', + 'p{color:khaki}', + ); return $tests; }