OSDN Git Service

update wp_imgswap.py
authorhylom <hylom@hylom.net>
Thu, 18 Apr 2013 10:35:27 +0000 (19:35 +0900)
committerhylom <hylom@hylom.net>
Thu, 18 Apr 2013 10:35:27 +0000 (19:35 +0900)
wp_imgswap.py [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index d8d19a4..b5a3b88
@@ -19,6 +19,7 @@ usage = """usage: %s <target file> <output_file> <image_dir> [link_prefix] [imag
 rex_imgtag = re.compile(r"""<img\s+src=["'](.*?)["'].*?>""")
 rex_atag = re.compile(r"""<a\s+href=["'](.*?)["'].*?>""")
 rex_alt = re.compile(r"""alt=["'](.*?)["']""")
+rex_figuretag = re.compile(r"""<figure\s+style=["'](.*?)["'].*?>""")
 
 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,