-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow custom handling of <script> and <style> #16
Comments
Use case: import subprocess
import htmlmin
def handle_pre(tag, data):
if tag == 'script':
process = subprocess.Popen('uglifyjs --compress --mangle --comments'.split(),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
data = process.communicate(input=data.encode('utf-8'))[0].decode('utf-8')
return data
print(htmlmin.minify('''...''', handle_pre=handle_pre)) |
This seems like a reasonable proposal and, hopefully, straightforward to implement. I might refer to the attribute as "pre_content_processor". We'll need to decide whether the callback gets called multiple times for nested pre-content. I lean towards only calling it once for the top-most pre-tag. If you'd like to submit a pull-request, I'd be happy to review it. Be sure to include tests. I can't promise an estimate for delivering this myself. |
I have implemented one that just calls the function for every handle_data (which is good enough for style/script). Making it into one call for top-most tag seems very difficult to me, but it sure would be better. |
I realize that the changes I made are very minor. This will not be useful for anything outside I am not planning to keep working on this. Thanks for considering this issue. |
This. It would be nice if (Minifying CSS would probably be easy to implement if I were to guess) |
This would be very good to have. There are already javascript and css minifiers for python available -- maybe those could be hooked in automatically? |
It would be very useful to allow some kind of callbacks that let the user handle CSS and JS in whatever way they want, instead of just leaving them unminified.
The text was updated successfully, but these errors were encountered: