Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: grit/format/html_inline.py

Issue 12036024: Fix the regex flatting html to prevent misdetection (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | grit/format/html_inline_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 # Check conditional elements, second pass. This catches conditionals in any 287 # Check conditional elements, second pass. This catches conditionals in any
288 # of the text we just inlined. 288 # of the text we just inlined.
289 flat_text = CheckConditionalElements(flat_text) 289 flat_text = CheckConditionalElements(flat_text)
290 290
291 # Allow custom modifications before inlining images. 291 # Allow custom modifications before inlining images.
292 if rewrite_function: 292 if rewrite_function:
293 flat_text = rewrite_function(input_filepath, flat_text, distribution) 293 flat_text = rewrite_function(input_filepath, flat_text, distribution)
294 294
295 flat_text = re.sub( 295 flat_text = re.sub(
296 '<(?!script)[^>]+?src=(?P<quote>")(?P<filename>[^"\']*)\\1', 296 '<(?!script)(?:[^>]+?\s)src=(?P<quote>")(?P<filename>[^"\']*)\\1',
297 SrcReplace, flat_text) 297 SrcReplace, flat_text)
298 298
299 # TODO(arv): Only do this inside <style> tags. 299 # TODO(arv): Only do this inside <style> tags.
300 flat_text = InlineCSSImages(flat_text) 300 flat_text = InlineCSSImages(flat_text)
301 301
302 flat_text = re.sub( 302 flat_text = re.sub(
303 '<link rel="icon".+?href=(?P<quote>")(?P<filename>[^"\']*)\\1', 303 '<link rel="icon"\s(?:[^>]+?\s)?href=(?P<quote>")(?P<filename>[^"\']*)\\1' ,
304 SrcReplace, flat_text) 304 SrcReplace, flat_text)
305 305
306 if names_only: 306 if names_only:
307 flat_text = None # Will contains garbage if the flag is set anyway. 307 flat_text = None # Will contains garbage if the flag is set anyway.
308 return InlinedData(flat_text, inlined_files) 308 return InlinedData(flat_text, inlined_files)
309 309
310 310
311 def InlineToString(input_filename, grd_node, allow_external_script=False, 311 def InlineToString(input_filename, grd_node, allow_external_script=False,
312 rewrite_function=None): 312 rewrite_function=None):
313 """Inlines the resources in a specified file and returns it as a string. 313 """Inlines the resources in a specified file and returns it as a string.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 def main(): 365 def main():
366 if len(sys.argv) <= 2: 366 if len(sys.argv) <= 2:
367 print "Flattens a HTML file by inlining its external resources.\n" 367 print "Flattens a HTML file by inlining its external resources.\n"
368 print "html_inline.py inputfile outputfile" 368 print "html_inline.py inputfile outputfile"
369 else: 369 else:
370 InlineToFile(sys.argv[1], sys.argv[2], None) 370 InlineToFile(sys.argv[1], sys.argv[2], None)
371 371
372 if __name__ == '__main__': 372 if __name__ == '__main__':
373 main() 373 main()
OLDNEW
« no previous file with comments | « no previous file | grit/format/html_inline_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698