Created
December 12, 2016 20:41
-
-
Save radius/0fff1869d93b753134f59e1da401d869 to your computer and use it in GitHub Desktop.
Premailer Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import premailer | |
def parse_template_tags(input_str): | |
""" Premailer encodes paths in the src attribute of images, so we have to swap them out w original values here """ | |
mapping = ( | |
('%7B%7B%20', '{{ '), ('%20%7D%7D', ' }}'), | |
('%7B%7B', '{{ '), ('%7D%7D', ' }}'), | |
) | |
for k, v in mapping: | |
input_str = input_str.replace(k, v) | |
return input_str | |
with open('input.html', 'r') as myfile: | |
data = myfile.read() | |
output = premailer.transform(data) | |
output = parse_template_tags(output) | |
print output | |
target = open('output.html', 'w') | |
target.write(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment