OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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. It recursively inlines the included files. | 10 dependencies. It recursively inlines the included files. |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 # Matches beginning of an "if" block with trailing spaces. | 26 # Matches beginning of an "if" block with trailing spaces. |
27 _BEGIN_IF_BLOCK = lazy_re.compile( | 27 _BEGIN_IF_BLOCK = lazy_re.compile( |
28 '<if [^>]*?expr="(?P<expression>[^"]*)"[^>]*?>\s*') | 28 '<if [^>]*?expr="(?P<expression>[^"]*)"[^>]*?>\s*') |
29 | 29 |
30 # Matches ending of an "if" block with preceding spaces. | 30 # Matches ending of an "if" block with preceding spaces. |
31 _END_IF_BLOCK = lazy_re.compile('\s*</if>') | 31 _END_IF_BLOCK = lazy_re.compile('\s*</if>') |
32 | 32 |
33 # Used by DoInline to replace various links with inline content. | 33 # Used by DoInline to replace various links with inline content. |
34 _STYLESHEET_RE = lazy_re.compile( | 34 _STYLESHEET_RE = lazy_re.compile( |
35 '<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>', | 35 '<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?', |
36 re.MULTILINE) | 36 re.DOTALL) |
37 _INCLUDE_RE = lazy_re.compile( | 37 _INCLUDE_RE = lazy_re.compile( |
38 '<include[^>]+?src="(?P<filename>[^"\']*)".*>', | 38 '<include[^>]+?src="(?P<filename>[^"\']*)".*?>(\s*</include>)?', |
39 re.MULTILINE) | 39 re.DOTALL) |
40 _SRC_RE = lazy_re.compile( | 40 _SRC_RE = lazy_re.compile( |
41 r'<(?!script)(?:[^>]+?\s)src=(?P<quote>")(?P<filename>[^"\']*)\1', | 41 r'<(?!script)(?:[^>]+?\s)src=(?P<quote>")(?P<filename>[^"\']*)\1', |
42 re.MULTILINE) | 42 re.MULTILINE) |
43 _ICON_RE = lazy_re.compile( | 43 _ICON_RE = lazy_re.compile( |
44 r'<link rel="icon"\s(?:[^>]+?\s)?' | 44 r'<link rel="icon"\s(?:[^>]+?\s)?' |
45 'href=(?P<quote>")(?P<filename>[^"\']*)\1', | 45 'href=(?P<quote>")(?P<filename>[^"\']*)\1', |
46 re.MULTILINE) | 46 re.MULTILINE) |
47 | 47 |
48 | 48 |
49 | 49 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 412 |
413 def main(): | 413 def main(): |
414 if len(sys.argv) <= 2: | 414 if len(sys.argv) <= 2: |
415 print "Flattens a HTML file by inlining its external resources.\n" | 415 print "Flattens a HTML file by inlining its external resources.\n" |
416 print "html_inline.py inputfile outputfile" | 416 print "html_inline.py inputfile outputfile" |
417 else: | 417 else: |
418 InlineToFile(sys.argv[1], sys.argv[2], None) | 418 InlineToFile(sys.argv[1], sys.argv[2], None) |
419 | 419 |
420 if __name__ == '__main__': | 420 if __name__ == '__main__': |
421 main() | 421 main() |
OLD | NEW |