From 9204d7faf17f515fcf2477f7f890be279706626e Mon Sep 17 00:00:00 2001 From: hylom Date: Thu, 18 Apr 2013 19:35:27 +0900 Subject: [PATCH] update wp_imgswap.py --- wp_imgswap.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) mode change 100755 => 100644 wp_imgswap.py diff --git a/wp_imgswap.py b/wp_imgswap.py old mode 100755 new mode 100644 index d8d19a4..b5a3b88 --- a/wp_imgswap.py +++ b/wp_imgswap.py @@ -19,6 +19,7 @@ usage = """usage: %s [link_prefix] [imag rex_imgtag = re.compile(r"""""") rex_atag = re.compile(r"""""") rex_alt = re.compile(r"""alt=["'](.*?)["']""") +rex_figuretag = re.compile(r"""""") try: in_f = codecs.open(sys.argv[1], "r", "utf_8" ) @@ -102,6 +103,13 @@ def replace_a_tag(line, tagstr, path): return line.replace(tagstr, new_tag_str) +def replace_figure_tag(line, tagstr, path): + attrs = htmltaglib.parse_attributes(tagstr) + attrs['style'] = "width:480px;" + new_tag_str = htmltaglib.build_tag('figure', attrs) + + return line.replace(tagstr, new_tag_str) + for line in in_f: # proc for IMG tag match = rex_imgtag.search(line) @@ -117,4 +125,11 @@ for line in in_f: path = match.group(1) line = replace_a_tag(line, tagstr, path) + #proc for FIGURE tag + match = rex_figuretag.search(line) + if match: + tagstr = match.group(0) + style= match.group(1) + line = replace_figure_tag(line, tagstr, style) + print >> out_f, line, -- 2.11.0