Skip to content

Commit

Permalink
Merge pull request #22 from oliverklee/cleanup/indentation
Browse files Browse the repository at this point in the history
[CLEANUP] Clean up the indentation levels.
  • Loading branch information
jjriv committed Jan 23, 2014
2 parents 082aa25 + ec03adb commit bb465a9
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,36 +375,35 @@ private function translateCsstoXpath($cssSelector) {
if (!isset($this->caches[CACHE_XPATH][$xpathKey])) {
// returns an Xpath selector
$search = array(
// Matches any element that is a child of parent.
'/\\s+>\\s+/',
// Matches any element that is an adjacent sibling.
'/\\s+\\+\\s+/',
// Matches any element that is a descendant of an parent element element.
'/\\s+/',
// first-child pseudo-selector
'/([^\\/]+):first-child/i',
// last-child pseudo-selector
'/([^\\/]+):last-child/i',
// Matches element with attribute
'/(\\w)\\[(\\w+)\\]/',
// Matches element with EXACT attribute
'/(\\w)\\[(\\w+)\\=[\'"]?(\\w+)[\'"]?\\]/',
// Matches id attributes
'/(\\w+)?\\#([\\w\\-]+)/e',
// Matches class attributes
'/(\\w+|[\\*\\]])?((\\.[\\w\\-]+)+)/e',

// Matches any element that is a child of parent.
'/\\s+>\\s+/',
// Matches any element that is an adjacent sibling.
'/\\s+\\+\\s+/',
// Matches any element that is a descendant of an parent element element.
'/\\s+/',
// first-child pseudo-selector
'/([^\\/]+):first-child/i',
// last-child pseudo-selector
'/([^\\/]+):last-child/i',
// Matches element with attribute
'/(\\w)\\[(\\w+)\\]/',
// Matches element with EXACT attribute
'/(\\w)\\[(\\w+)\\=[\'"]?(\\w+)[\'"]?\\]/',
// Matches id attributes
'/(\\w+)?\\#([\\w\\-]+)/e',
// Matches class attributes
'/(\\w+|[\\*\\]])?((\\.[\\w\\-]+)+)/e',
);
$replace = array(
'/',
'/following-sibling::*[1]/self::',
'//',
'*[1]/self::\\1',
'*[last()]/self::\\1',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
"(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
"(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
'/',
'/following-sibling::*[1]/self::',
'//',
'*[1]/self::\\1',
'*[last()]/self::\\1',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
"(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
"(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
);

$cssSelector = '//'.preg_replace($search, $replace, $cssSelector);
Expand Down Expand Up @@ -468,8 +467,8 @@ private function parseNth(array $match) {
if (in_array(strtolower($match[2]), array('even','odd'))) {
$index = strtolower($match[2]) == 'even' ? 0 : 1;
return array(self::MULTIPLIER => 2, self::INDEX => $index);
// if there is a multiplier
} elseif (stripos($match[2], 'n') === FALSE) {
// if there is a multiplier
$index = intval(str_replace(' ', '', $match[2]));
return array(self::INDEX => $index);
} else {
Expand Down

0 comments on commit bb465a9

Please sign in to comment.