Chromium Code Reviews| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 | 177 |
| 178 def IsConditionSatisfied(src_match): | 178 def IsConditionSatisfied(src_match): |
| 179 expression = src_match.group('expression') | 179 expression = src_match.group('expression') |
| 180 return grd_node is None or grd_node.EvaluateCondition(expression) | 180 return grd_node is None or grd_node.EvaluateCondition(expression) |
| 181 | 181 |
| 182 def CheckConditionalElements(str): | 182 def CheckConditionalElements(str): |
| 183 """Helper function to conditionally inline inner elements""" | 183 """Helper function to conditionally inline inner elements""" |
| 184 while True: | 184 while True: |
| 185 begin_if = _BEGIN_IF_BLOCK.search(str) | 185 begin_if = _BEGIN_IF_BLOCK.search(str) |
| 186 if begin_if is None: | 186 if begin_if is None: |
| 187 if _END_IF_BLOCK.search(str) is not None: | |
| 188 raise Exception('Unexpected </if>') | |
|
Nico
2015/03/26 17:58:56
Should this be 'Unmatched </if>' to match the simi
| |
| 187 return str | 189 return str |
| 188 | 190 |
| 189 condition_satisfied = IsConditionSatisfied(begin_if) | 191 condition_satisfied = IsConditionSatisfied(begin_if) |
| 190 leading = str[0:begin_if.start()] | 192 leading = str[0:begin_if.start()] |
| 191 content_start = begin_if.end() | 193 content_start = begin_if.end() |
| 192 | 194 |
| 193 # Find matching "if" block end. | 195 # Find matching "if" block end. |
| 194 count = 1 | 196 count = 1 |
| 195 pos = begin_if.end() | 197 pos = begin_if.end() |
| 196 while True: | 198 while True: |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 | 414 |
| 413 def main(): | 415 def main(): |
| 414 if len(sys.argv) <= 2: | 416 if len(sys.argv) <= 2: |
| 415 print "Flattens a HTML file by inlining its external resources.\n" | 417 print "Flattens a HTML file by inlining its external resources.\n" |
| 416 print "html_inline.py inputfile outputfile" | 418 print "html_inline.py inputfile outputfile" |
| 417 else: | 419 else: |
| 418 InlineToFile(sys.argv[1], sys.argv[2], None) | 420 InlineToFile(sys.argv[1], sys.argv[2], None) |
| 419 | 421 |
| 420 if __name__ == '__main__': | 422 if __name__ == '__main__': |
| 421 main() | 423 main() |
| OLD | NEW |