diff --git a/premailer/merge_style.py b/premailer/merge_style.py index 0fe93f7..9842e63 100644 --- a/premailer/merge_style.py +++ b/premailer/merge_style.py @@ -1,5 +1,6 @@ import cssutils import threading +from operator import itemgetter def csstext_to_pairs(csstext): @@ -10,11 +11,10 @@ def csstext_to_pairs(csstext): # The lock is required to avoid ``cssutils`` concurrency # issues documented in issue #65 with csstext_to_pairs._lock: - parsed = cssutils.css.CSSVariablesDeclaration(csstext) - return [ - (key.strip(), parsed.getVariableValue(key).strip()) - for key in sorted(parsed) - ] + return sorted([(prop.name.strip(), prop.propertyValue.cssText.strip()) + for prop in cssutils.parseStyle(csstext)], + key=itemgetter(0)) + csstext_to_pairs._lock = threading.RLock() diff --git a/premailer/tests/test_merge_style.py b/premailer/tests/test_merge_style.py index 7a8a215..0d4d11f 100644 --- a/premailer/tests/test_merge_style.py +++ b/premailer/tests/test_merge_style.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, unicode_literals import unittest -import xml -from nose.tools import raises from premailer.merge_style import csstext_to_pairs, merge_styles @@ -14,9 +12,13 @@ class TestMergeStyle(unittest.TestCase): parsed_csstext = csstext_to_pairs(csstext) self.assertEqual(('font-size', '1px'), parsed_csstext[0]) - @raises(xml.dom.SyntaxErr) def test_inline_invalid_syntax(self): - # inline shouldn't have those as I understand - # but keep the behaviour + # Invalid syntax does not raise inline = '{color:pink} :hover{color:purple} :active{color:red}' merge_styles(inline, [], []) + + def test_important_rule(self): + # No exception after #133 + csstext = 'font-size:1px !important' + parsed_csstext = csstext_to_pairs(csstext) + self.assertEqual(('font-size', '1px'), parsed_csstext[0])