private function mimemail_compress::css_to_xpath in Mime Mail 7
Same name and namespace in other branches
- 6 modules/mimemail_compress/mimemail_compress.inc \mimemail_compress::css_to_xpath()
Right now we only support CSS 1 selectors, but include CSS2/3 selectors are fully possible.
See also
http://plasmasturm.org/log/444
1 call to mimemail_compress::css_to_xpath()
- mimemail_compress::compress in modules/
mimemail_compress/ mimemail_compress.inc
File
- modules/
mimemail_compress/ mimemail_compress.inc, line 265 - Converts CSS styles into inline style attributes.
Class
- mimemail_compress
- Compresses HTML and CSS into combined message.
Code
private function css_to_xpath($selector) {
if (drupal_substr($selector, 0, 1) == '/') {
// Already an XPath expression.
return $selector;
}
// Returns an Xpath selector.
$search = array(
'/\\s+>\\s+/',
// Matches any F element that is a child of an element E.
'/(\\w+)\\s+\\+\\s+(\\w+)/',
// Matches any F element that is a child of an element E.
'/\\s+/',
// Matches any F element that is a descendant of an E element.
'/(\\w)\\[(\\w+)\\]/',
// Matches element with attribute.
'/(\\w)\\[(\\w+)\\=[\'"]?(\\w+)[\'"]?\\]/',
);
$replace = array(
'/',
'\\1/following-sibling::*[1]/self::\\2',
'//',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
);
$result = preg_replace($search, $replace, trim($selector));
$result = preg_replace_callback('/(\\w+)?\\#([\\w\\-]+)/', 'mimemail_compress::replace_id_attributes', $result);
$result = preg_replace_callback('/(\\w+|\\*)?((\\.[\\w\\-]+)+)/', 'mimemail_compress::replace_class_attributes', $result);
return '//' . $result;
}