Repository: peterbe/premailer

Issue:
Unknown property names
Property: Unknown Property name. [31:17: -ms-interpolation-mode]
Property: Unknown Property name. [4:17: mso-line-height-rule]
Property: Unknown Property name. [106:17: -webkit-text-size-adjust]
Property: Unknown Property name. [107:17: -ms-text-size-adjust]
Property: Unknown Property name. [188:21: text-rendering]
Property: Unknown Property name. [613:17: mso-text-raise]
Property: Unknown Property name. [624:17: transition]
Property: Unknown Property name.

I'm not sure what is this and what can I do about that..
Thanks for any help!


Discussion:

Patch:
diff --git a/README.rst b/README.rst
index 272a0b9..a3af844 100644
--- a/README.rst
+++ b/README.rst
@@ -221,7 +221,38 @@ attribute ``bgcolor="#eee"``.
 Having these extra attributes basically as a "back up" for really shit
 email clients that can't even take the style attributes. A lot of
 professional HTML newsletters such as Amazon's use this. You can disable
-some attributes in ``disable_basic_attributes``
+some attributes in ``disable_basic_attributes``.
+
+
+Capturing logging from ``cssutils``
+-----------------------------------
+
+`cssutils <https://pypi.python.org/pypi/cssutils/>`__ is the library that
+``premailer`` uses to parse CSS. It will use the python ``logging`` module
+to mention all issues it has with parsing your CSS. If you want to capture
+this, you have to pass in ``cssutils_logging_handler`` and
+``cssutils_logging_level`` (optional). For example like this:
+
+.. code:: python
+
+    >>> import logging
+    >>> import premailer
+    >>> from io import StringIO
+    >>> mylog = StringIO()
+    >>> myhandler = logging.StreamHandler(mylog)
+    >>> p = premailer.Premailer("""
+    ...         <html>
+    ...         <style type="text/css">
+    ...         @keyframes foo { from { opacity: 0; } to { opacity: 1; } }
+    ...         </style>
+    ...         <p>Hej</p>
+    ...         </html>
+    ... """,
+    ... cssutils_logging_handler=myhandler,
+    ... cssutils_logging_level=logging.INFO)
+    >>> result = p.transform()
+    >>> mylog.getvalue()
+    'CSSStylesheet: Unknown @rule found. [2:1: @keyframes]\n'
 
 Running tests with tox
 ----------------------
diff --git a/premailer/premailer.py b/premailer/premailer.py
index e0ac5eb..4e5d49f 100644
--- a/premailer/premailer.py
+++ b/premailer/premailer.py
@@ -111,7 +111,9 @@ class Premailer(object):
                  base_path=None,
                  disable_basic_attributes=None,
                  disable_validation=False,
-                 cache_css_parsing=True):
+                 cache_css_parsing=True,
+                 cssutils_logging_handler=None,
+                 cssutils_logging_level=None):
         self.html = html
         self.base_url = base_url
         self.preserve_internal_links = preserve_internal_links
@@ -138,6 +140,11 @@ class Premailer(object):
         self.disable_validation = disable_validation
         self.cache_css_parsing = cache_css_parsing
 
+        if cssutils_logging_handler:
+            cssutils.log.addHandler(cssutils_logging_handler)
+        if cssutils_logging_level:
+            cssutils.log.setLevel(cssutils_logging_level)
+
     def _parse_css_string(self, css_body, validate=True):
         if self.cache_css_parsing:
             return _cache_parse_css_string(css_body, validate=validate)


Test patch:
diff --git a/premailer/tests/test_premailer.py b/premailer/tests/test_premailer.py
index 4390a4e..dd9c07e 100644
--- a/premailer/tests/test_premailer.py
+++ b/premailer/tests/test_premailer.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
 import sys
 import re
 import unittest
+import logging
 from contextlib import contextmanager
 if sys.version_info >= (3, ):  # As in, Python 3
     from urllib.request import urlopen
@@ -2124,6 +2125,47 @@ ent:"" !important;display:block !important}
         p = Premailer(html, disable_validation=True)
         p.transform()  # it should just work
 
+    def test_capture_cssutils_logging(self):
+        """you can capture all the warnings, errors etc. from cssutils
+        with your own logging. """
+        html = """<!doctype html>
+        <html>
+        <head>
+            <meta charset="UTF-8">
+            <title>Document</title>
+            <style>
+            @keyframes fadein {
+                from { opacity: 0; }
+                to   { opacity: 1; }
+            }
+            </style>
+        </head>
+        <body></body>
+        </html>"""
+
+        mylog = StringIO()
+        myhandler = logging.StreamHandler(mylog)
+        p = Premailer(
+            html,
+            cssutils_logging_handler=myhandler,
+        )
+        p.transform()  # it should work
+        eq_(
+            mylog.getvalue(),
+            'CSSStylesheet: Unknown @rule found. [2:13: @keyframes]\n'
+        )
+
+        # only log errors now
+        mylog = StringIO()
+        myhandler = logging.StreamHandler(mylog)
+        p = Premailer(
+            html,
+            cssutils_logging_handler=myhandler,
+            cssutils_logging_level=logging.ERROR,
+        )
+        p.transform()  # it should work
+        eq_(mylog.getvalue(), '')
+
     def test_type_test(self):
         """test the correct type is returned"""