-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to include images as inline data #219
Comments
You mean, base64 inlining? Like, Perhaps a "better" solution was if premailer could expose the parsed lxml document in some form so that you can make those kinds of manipulations yourself. Something like this: import base64
import premailer
p = premailer.Premailer(html_string)
for img in p.cssselect('img.thumbnail'):
fn = uri_to_local_file_path(img.attr('src'))
b64 = base64.b64encode(open(fn, "rb").read())
img.attr('src', f'data:image/png;base64,{b64}')
inlined_html = p.transform() That way, all feature requests, like this issue, would be relatively taken care of. Would you be interested in adding a feature like this @dov ? |
Due to organic slow growth the p = premailer.Premailer(html_string)
print(p.transform()) But, if you have many different html_strings you can instead share 1 instance for all, like: p = premailer.Premailer(**my_awesome_options)
for html_string in html_strings:
print(p.transform(html_string)) So it's not a dead obvious place where to put the preprocessing. But it could be like this: def my_mutating_pre_processor(instance):
assert instance is p # just for demonstration
for img in instance.cssselect('img.thumbnail'):
fn = uri_to_local_file_path(img.attr('src'))
b64 = base64.b64encode(open(fn, "rb").read())
img.attr('src', f'data:image/png;base64,{b64}')
p = premailer.Premailer(pre_processor=my_mutating_pre_processor, **my_awesome_options)
for html_string in html_strings:
print(p.transform(html_string)) Let me know if you're interested in writing a patch. I can help with running tests and design. |
This is indeed my intention, and your suggestion for an API through the pre_processor function certainly makes sense. If I start working on a patch for this, I'll let you know. |
Is there any news on this? |
Not that I know. I still stand by my 2019 comment above I guess. |
I'm currently using
npm install inliner
for embedding images in an html file into the document. This step is necessary for disconnecting the html from external references.It would be nice if premailer also had this option.
The text was updated successfully, but these errors were encountered: