| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Flattens a HTML file by inlining its external resources. | 6 """Flattens a HTML file by inlining its external resources. |
| 7 | 7 |
| 8 This is a small script that takes a HTML file, looks for src attributes | 8 This is a small script that takes a HTML file, looks for src attributes |
| 9 and inlines the specified file, producing one HTML file with no external | 9 and inlines the specified file, producing one HTML file with no external |
| 10 dependencies. | 10 dependencies. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 """Helper function to provide SrcInline with the base file path""" | 91 """Helper function to provide SrcInline with the base file path""" |
| 92 return SrcInline(src_match, input_filepath, distribution) | 92 return SrcInline(src_match, input_filepath, distribution) |
| 93 | 93 |
| 94 # TODO(glen): Make this regex not match src="" text that is not inside a tag | 94 # TODO(glen): Make this regex not match src="" text that is not inside a tag |
| 95 flat_text = re.sub('src="(?P<filename>[^"\']*)"', | 95 flat_text = re.sub('src="(?P<filename>[^"\']*)"', |
| 96 SrcReplace, | 96 SrcReplace, |
| 97 ReadFile(input_filename)) | 97 ReadFile(input_filename)) |
| 98 | 98 |
| 99 # TODO(glen): Make this regex not match url('') that is not inside a style | 99 # TODO(glen): Make this regex not match url('') that is not inside a style |
| 100 flat_text = re.sub('background:[ ]*url\(\'(?P<filename>[^"\']*)\'', | 100 flat_text = re.sub('background:[ ]*url\(\'(?P<filename>[^"\']*)\'', |
| 101 SrcReplace, | 101 SrcReplace, |
| 102 flat_text) | 102 flat_text) |
| 103 |
| 104 flat_text = re.sub('<link rel="icon".+?href="(?P<filename>[^"\']*)"', |
| 105 SrcReplace, |
| 106 flat_text) |
| 103 | 107 |
| 104 out_file = open(output_filename, 'wb') | 108 out_file = open(output_filename, 'wb') |
| 105 out_file.writelines(flat_text) | 109 out_file.writelines(flat_text) |
| 106 out_file.close() | 110 out_file.close() |
| 107 | 111 |
| 108 def main(): | 112 def main(): |
| 109 if len(sys.argv) <= 2: | 113 if len(sys.argv) <= 2: |
| 110 print "Flattens a HTML file by inlining its external resources.\n" | 114 print "Flattens a HTML file by inlining its external resources.\n" |
| 111 print "html_inline.py inputfile outputfile" | 115 print "html_inline.py inputfile outputfile" |
| 112 else: | 116 else: |
| 113 InlineFile(sys.argv[1], sys.argv[2]) | 117 InlineFile(sys.argv[1], sys.argv[2]) |
| 114 | 118 |
| 115 if __name__ == '__main__': | 119 if __name__ == '__main__': |
| 116 main() | 120 main() |
| 117 | |
| OLD | NEW |