From: hylom Date: Thu, 18 Apr 2013 10:35:27 +0000 (+0900) Subject: update wp_imgswap.py X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9204d7faf17f515fcf2477f7f890be279706626e;p=otptools%2Fotptools.git update 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,