Skip to content

Commit 8c0cf91

Browse files
committed
patch: adapting premailer 3.9 and above
peterbe/premailer@7dcee9e
1 parent 1176908 commit 8c0cf91

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

preprocess_cssless.diff

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py
2+
index 11170e3..0c29d96 100644
3+
--- a/commands/preprocess_cssless.py
4+
+++ b/commands/preprocess_cssless.py
5+
@@ -25,8 +25,11 @@ import warnings
6+
import cssutils
7+
from lxml import etree
8+
from lxml.etree import strip_elements
9+
+import premailer
10+
from premailer import Premailer
11+
12+
+premailer_version = premailer.__version__.split('.')
13+
+premailer_is_new=len(premailer_version) >= 2 and int(premailer_version[0]) >= 3 and int(premailer_version[1]) >= 9
14+
15+
def preprocess_html_merge_cssless(src_path, dst_path):
16+
with open(src_path, 'r', encoding='utf-8') as a_file:
17+
@@ -72,8 +75,13 @@ def preprocess_html_merge_css(root, src_path):
18+
19+
with warnings.catch_warnings():
20+
warnings.simplefilter("ignore")
21+
- premailer = Premailer(root, base_url=src_path,
22+
- disable_link_rewrites=True, remove_classes=True)
23+
+ if premailer_is_new:
24+
+ premailer = Premailer(root, base_url=src_path,
25+
+ disable_link_rewrites=True, remove_classes=True,
26+
+ allow_loading_external_files=True)
27+
+ else:
28+
+ premailer = Premailer(root, base_url=src_path,
29+
+ disable_link_rewrites=True, remove_classes=True)
30+
root = premailer.transform().getroot()
31+
32+
return output.getvalue()

0 commit comments

Comments
 (0)