Skip to content

Instantly share code, notes, and snippets.

@radius
Created December 12, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radius/0fff1869d93b753134f59e1da401d869 to your computer and use it in GitHub Desktop.
Save radius/0fff1869d93b753134f59e1da401d869 to your computer and use it in GitHub Desktop.
Premailer Usage
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