graingert: I think it's such a trivial and unlikely to be used piece of code, that I'd rather just remove it and recommend people add their own:
```python
            # now we can delete all 'class' attributes
            for item in page.xpath('//@class'):
                parent = item.getparent()
                del parent.attrib['class']
```


peterbe: @graingert But I want the library to be as easy as possible. Also, as lazy as possible :)
graingert: It's your call, but imagine if this feature was not implemented, would it be worth adding?

I don't see a use-case for it.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/6493685/badge)](https://coveralls.io/builds/6493685)

Coverage decreased (-0.7%) to 99.299% when pulling **4e1762899aca476de755ada50c95ec02072e24db on keep-classes-by-default-fixes-33** into **cc18022e334d5336e48f75bd4e0a73c98cc5942a on master**.

peterbe: One usecase is that it's not hard to keep and it's nice to have it there
for people who needed it.

Actually, if you don't have media queries. If you have some really simple
CSS for your HTML emails, then having the `class` attributes still in means
the email gets unnecessarily larger.
I suggest we just keep the functionality around.

On Tue, Jun 7, 2016 at 8:45 AM, Thomas Grainger <notifications@github.com>
wrote:

> It's your call, but imagine if this feature was not implemented, would it
> be worth adding?
>
> I don't see a use-case for it.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/peterbe/premailer/pull/167#issuecomment-224269061>,
> or mute the thread
> <https://github.com/notifications/unsubscribe/AABoc_2Fg2_REhvGVNqOZLI7Z5RBUWkLks5qJWfjgaJpZM4Iv3_H>
> .
>



-- 
Peter Bengtsson
Mozilla Tools & Services

coveralls: 
[![Coverage Status](https://coveralls.io/builds/6493757/badge)](https://coveralls.io/builds/6493757)

Coverage remained the same at 100.0% when pulling **6e9df1c5587d133851f2185c63cf79998ad679ec on keep-classes-by-default-fixes-33** into **cc18022e334d5336e48f75bd4e0a73c98cc5942a on master**.

diff --git a/premailer/__init__.py b/premailer/__init__.py
index e831baa..570b55c 100644
--- a/premailer/__init__.py
+++ b/premailer/__init__.py
@@ -1,4 +1,4 @@
 from __future__ import absolute_import, unicode_literals
 from .premailer import Premailer, transform
 
-__version__ = '2.11.0'
+__version__ = '3.0.0'
diff --git a/premailer/premailer.py b/premailer/premailer.py
index de9839d..fc157ee 100644
--- a/premailer/premailer.py
+++ b/premailer/premailer.py
@@ -121,7 +121,7 @@ class Premailer(object):
                  exclude_pseudoclasses=True,
                  keep_style_tags=False,
                  include_star_selectors=False,
-                 remove_classes=True,
+                 remove_classes=False,
                  capitalize_float_margin=False,
                  strip_important=True,
                  external_styles=None,

keep class attributes
the transform() function replaces the "class" attribute with the appropriate styling, but it also removes the class from the html elements. I need the styling added inline, but the classes to be left within their elements so that my @media (!important) styling can be inserted in after and still have classes to point to within the dom.

Im having a hard time changing your code to meet this needs, do you have any thoughts on how I could keep the classes within the html elements but still inject the inline styling?
diff --git a/premailer/tests/test_premailer.py b/premailer/tests/test_premailer.py
index 42213d8..5cdf6a7 100644
--- a/premailer/tests/test_premailer.py
+++ b/premailer/tests/test_premailer.py
@@ -170,6 +170,37 @@ class Tests(unittest.TestCase):
 
         compare_html(expect_html, result_html)
 
+    def test_remove_classes(self):
+        """test the simplest case"""
+
+        html = """<html>
+        <head>
+        <title>Title</title>
+        <style type="text/css">
+        .stuff {
+            color: red;
+        }
+        </style>
+        </head>
+        <body>
+        <p class="stuff"><strong>Yes!</strong></p>
+        </body>
+        </html>"""
+
+        expect_html = """<html>
+        <head>
+        <title>Title</title>
+        </head>
+        <body>
+        <p style="color:red"><strong>Yes!</strong></p>
+        </body>
+        </html>"""
+
+        p = Premailer(html, remove_classes=True)
+        result_html = p.transform()
+
+        compare_html(expect_html, result_html)
+
     def test_basic_html_shortcut_function(self):
         """test the plain transform function"""
         html = """<html>
@@ -1088,7 +1119,7 @@ b
         <head>
         </head>
         <body>
-        <div style="color:red"></div>
+        <div class="example" style="color:red"></div>
         </body>
         </html>"""
 
@@ -1118,7 +1149,7 @@ b
         <head>
         </head>
         <body>
-        <div style="color:green"></div>
+        <div class="example" style="color:green"></div>
         </body>
         </html>"""
 
@@ -1148,7 +1179,7 @@ b
         <head>
         </head>
         <body>
-        <div style="color:green"></div>
+        <div class="example" style="color:green"></div>
         </body>
         </html>"""
 
@@ -1178,7 +1209,7 @@ b
         <head>
         </head>
         <body>
-        <div id="identified" style="color:green"></div>
+        <div class="example" id="identified" style="color:green"></div>
         </body>
         </html>"""
 
@@ -1195,7 +1226,7 @@ b
             color: blue !important;
             font-size: 12px;
         }
-        #identified {
+        #id {
             color: green;
             font-size: 22px;
         }
@@ -1205,17 +1236,17 @@ b
         </style>
         </head>
         <body>
-        <div class="example makeblue" id="identified"></div>
+        <div class="example makeblue" id="id"></div>
         </body>
         </html>"""
 
         expect_html = """<html>
-        <head>
-        </head>
-        <body>
-        <div id="identified" style="font-size:22px; color:blue"></div>
-        </body>
-        </html>"""
+<head>
+</head>
+<body>
+<div class="example makeblue" id="id" style="font-size:22px; color:blue"></div>
+</body>
+</html>"""
 
         p = Premailer(html)
         result_html = p.transform()
@@ -1285,7 +1316,7 @@ ration:none">Yes!</strong></p>
         <title>Title</title>
         </head>
         <body>
-        <h1 style="color:green">Hi!</h1>
+        <h1 class="foo" style="color:green">Hi!</h1>
         </body>
         </html>"""
 
@@ -2395,7 +2426,7 @@ sheet" type="text/css">
         <head>
         </head>
         <body>
-        <div style="color:green; font-size:10px"></div>
+        <div class="color example" style="color:green; font-size:10px"></div>
         </body>
         </html>"""
 
@@ -2453,22 +2484,22 @@ sheet" type="text/css">
         </head>
         <body>
         <p><img src="/images/left.jpg" style="float: left"> text
-           <img src="/images/right.png" class="floatright"> text
+           <img src="/r.png" class="floatright"> text
            <img src="/images/nofloat.gif"> text
         </body>
         </html>"""
 
         expect_html = """<html>
-        <head>
-        <title>Title</title>
-        </head>
-        <body>
-        <p><img src="/images/left.jpg" style="float: left" align="left"> text
-           <img src="/images/right.png" style="float:right" align="right"> text
-           <img src="/images/nofloat.gif"> text
-        </p>
-        </body>
-        </html>"""
+<head>
+<title>Title</title>
+</head>
+<body>
+<p><img src="/images/left.jpg" style="float: left" align="left"> text
+   <img src="/r.png" class="floatright" style="float:right" align="right"> text
+   <img src="/images/nofloat.gif"> text
+</p>
+</body>
+</html>"""
 
         p = Premailer(html, align_floating_images=True)
         result_html = p.transform()
@@ -2498,7 +2529,8 @@ sheet" type="text/css">
         <head>
         </head>
         <body>
-        <div style="color:green"><span></span></div>
+        <div class="color" style="color:green"><span class="nocolor"></span>
+        </div>
         </body>
         </html>"""
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
nose mock coverage pytest
3.5
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
cssselect==1.1.0
cssutils==2.3.1
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
lxml==5.3.1
mock==5.2.0
nose==1.3.7
packaging==21.3
pluggy==1.0.0
-e git+https://github.com/peterbe/premailer.git@cc18022e334d5336e48f75bd4e0a73c98cc5942a#egg=premailer
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
requests==2.27.1
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
zipp==3.6.0

name: premailer
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - cssselect==1.1.0
      - cssutils==2.3.1
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - lxml==5.3.1
      - mock==5.2.0
      - nose==1.3.7
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - requests==2.27.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - zipp==3.6.0
prefix: /opt/conda/envs/premailer

premailer/tests/test_premailer.py::Tests::test_align_float_images premailer/tests/test_premailer.py::Tests::test_favour_rule_with_class_over_generic premailer/tests/test_premailer.py::Tests::test_favour_rule_with_element_over_generic premailer/tests/test_premailer.py::Tests::test_favour_rule_with_id_over_others premailer/tests/test_premailer.py::Tests::test_favour_rule_with_important_over_others premailer/tests/test_premailer.py::Tests::test_prefer_inline_to_class premailer/tests/test_premailer.py::Tests::test_remove_unset_properties premailer/tests/test_premailer.py::Tests::test_style_attribute_specificity premailer/tests/test_premailer.py::Tests::test_turnoff_cache_works_as_expected
premailer/tests/test_premailer.py::Tests::test_3_digit_color_expand premailer/tests/test_premailer.py::Tests::test_apple_newsletter_example premailer/tests/test_premailer.py::Tests::test_base_url_fixer premailer/tests/test_premailer.py::Tests::test_base_url_with_path premailer/tests/test_premailer.py::Tests::test_basic_html premailer/tests/test_premailer.py::Tests::test_basic_html_shortcut_function premailer/tests/test_premailer.py::Tests::test_basic_html_with_pseudo_selector premailer/tests/test_premailer.py::Tests::test_basic_xml premailer/tests/test_premailer.py::Tests::test_broken_xml premailer/tests/test_premailer.py::Tests::test_capture_cssutils_logging premailer/tests/test_premailer.py::Tests::test_child_selector premailer/tests/test_premailer.py::Tests::test_command_line_fileinput_from_argument premailer/tests/test_premailer.py::Tests::test_command_line_fileinput_from_stdin premailer/tests/test_premailer.py::Tests::test_command_line_preserve_style_tags premailer/tests/test_premailer.py::Tests::test_comments_in_media_queries premailer/tests/test_premailer.py::Tests::test_css_disable_basic_html_attributes premailer/tests/test_premailer.py::Tests::test_css_disable_leftover_css premailer/tests/test_premailer.py::Tests::test_css_text premailer/tests/test_premailer.py::Tests::test_css_text_with_only_body_present premailer/tests/test_premailer.py::Tests::test_css_with_html_attributes premailer/tests/test_premailer.py::Tests::test_css_with_pseudoclasses_excluded premailer/tests/test_premailer.py::Tests::test_css_with_pseudoclasses_included premailer/tests/test_premailer.py::Tests::test_disabled_validator premailer/tests/test_premailer.py::Tests::test_doctype premailer/tests/test_premailer.py::Tests::test_empty_style_tag premailer/tests/test_premailer.py::Tests::test_external_links premailer/tests/test_premailer.py::Tests::test_external_links_unfindable premailer/tests/test_premailer.py::Tests::test_external_styles_and_links premailer/tests/test_premailer.py::Tests::test_external_styles_on_http premailer/tests/test_premailer.py::Tests::test_external_styles_on_https premailer/tests/test_premailer.py::Tests::test_external_styles_with_base_url premailer/tests/test_premailer.py::Tests::test_fontface_selectors_with_no_selectortext premailer/tests/test_premailer.py::Tests::test_ignore_some_external_stylesheets premailer/tests/test_premailer.py::Tests::test_ignore_some_incorrectly premailer/tests/test_premailer.py::Tests::test_ignore_some_inline_stylesheets premailer/tests/test_premailer.py::Tests::test_ignore_style_elements_with_media_attribute premailer/tests/test_premailer.py::Tests::test_include_star_selector premailer/tests/test_premailer.py::Tests::test_inline_important premailer/tests/test_premailer.py::Tests::test_inline_wins_over_external premailer/tests/test_premailer.py::Tests::test_keyframe_selectors premailer/tests/test_premailer.py::Tests::test_last_child premailer/tests/test_premailer.py::Tests::test_last_child_exclude_pseudo premailer/tests/test_premailer.py::Tests::test_leftover_important premailer/tests/test_premailer.py::Tests::test_links_without_protocol premailer/tests/test_premailer.py::Tests::test_load_external_url premailer/tests/test_premailer.py::Tests::test_mailto_url premailer/tests/test_premailer.py::Tests::test_mediaquery premailer/tests/test_premailer.py::Tests::test_merge_styles_basic premailer/tests/test_premailer.py::Tests::test_merge_styles_non_trivial premailer/tests/test_premailer.py::Tests::test_merge_styles_with_class premailer/tests/test_premailer.py::Tests::test_merge_styles_with_unset premailer/tests/test_premailer.py::Tests::test_mixed_pseudo_selectors premailer/tests/test_premailer.py::Tests::test_multiple_style_elements premailer/tests/test_premailer.py::Tests::test_multithreading premailer/tests/test_premailer.py::Tests::test_parse_style_rules premailer/tests/test_premailer.py::Tests::test_precedence_comparison premailer/tests/test_premailer.py::Tests::test_remove_classes premailer/tests/test_premailer.py::Tests::test_shortcut_function premailer/tests/test_premailer.py::Tests::test_six_color premailer/tests/test_premailer.py::Tests::test_strip_important premailer/tests/test_premailer.py::Tests::test_style_block_with_external_urls premailer/tests/test_premailer.py::Tests::test_type_test premailer/tests/test_premailer.py::Tests::test_uppercase_margin premailer/tests/test_premailer.py::Tests::test_xml_cdata
premailer/__init__.py premailer/premailer.py
premailer/__init__.py premailer/premailer.py