OSDN Git Service

add th support for "".
authorhylom <hylom@users.sourceforge.jp>
Tue, 6 Oct 2009 09:11:43 +0000 (18:11 +0900)
committerhylom <hylom@users.sourceforge.jp>
Tue, 6 Oct 2009 09:11:43 +0000 (18:11 +0900)
markupper.py

index 41aadc9..826c0cd 100755 (executable)
@@ -134,6 +134,9 @@ class Markupper(object):
             elif re.search(ur"^☆図", line):
                 self._fig(line)
                 continue
+            elif re.search(ur"^☆写真", line):
+                self._photo(line)
+                continue
             elif re.search(ur"^☆リスト", line):
                 self._list(line)
                 continue
@@ -267,6 +270,7 @@ class Markupper(object):
 
         line = re.sub(ur"[★*](表[0-9~、]+)", ur"<b>\1</b>", line)
         line = re.sub(ur"[★*](図[0-9~、]+)", ur"<b>\1</b>", line)
+        line = re.sub(ur"[★*](写真[0-9~、]+)", ur"<b>\1</b>", line)
         line = re.sub(ur"[★*](リスト[0-9~、]+)", ur"<b>\1</b>", line)
         line = re.sub(ur"[★*]b\[(.*?)\]", ur"<b>\1</b>", line)
         line = re.sub(ur"[★*]b\{(.*?)\}", ur"<b>\1</b>", line)
@@ -497,6 +501,50 @@ class Markupper(object):
         if imgname_s != "":
             dic.append(imgname_s)
 
+    def _photo(self, line):
+        try:
+            str_title = re.search(ur"^☆(写真.*)$", line).group(1)
+        except AttributeError:
+            str_title = ""
+        if str_title.find(u"写真*") == 0:
+            str_title = str_title.replace(u"写真*", "")
+        line = self.input_iter.next()
+        styles = []
+        if line.find("@") == 0:
+            styles = line.strip().replace("@", "").split(",")
+            line = self.input_iter.next()
+
+        imgname = ""
+        imgname_s = ""
+        hash = ""
+        hash_s = ""
+        match_o1 = re.search(ur"<([^,]*?)>", line)
+        match_o2 = re.search(ur"<(.*?),\s*(.*?)>", line)
+        if not match_o1 == None:
+            imgname = match_o1.group(1)
+            imgname = os.path.join(self._image_dir, imgname)
+            imgname_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", imgname)
+        elif not match_o2 == None:
+            imgname = match_o2.group(1)
+            imgname = os.path.join(self._image_dir, imgname)
+            imgname_s = match_o2.group(2)
+            imgname_s = os.path.join(self._image_dir, imgname_s)
+
+        geom = self._get_png_geom(imgname_s)
+        if geom:
+            w = geom[0]
+            h = geom[1]
+            print self._fig_start("", styles, width=w, height=h)
+        else:
+            print self._fig_start("", styles)
+        print self._anchored_fig(imgname, str_title, imgname_s)
+        print self._fig_end(str_title, styles);
+
+        dic = self.index("figs")
+        dic.append(imgname)
+        if imgname_s != "":
+            dic.append(imgname_s)
+
         
     def _anchored_fig(self, file, alt, file_s=""):
 
@@ -590,7 +638,6 @@ class Markupper(object):
             if re.search(ur"^※", line):
                 footnote = re.search(ur"^(※.*)$", line).group(1)
                 break
-            line = self._default_markup_rule(line)
             if re.search(ur"^〓", line):
                 line = re.sub(ur"^〓", "", line)
                 tag_mode = "th"
@@ -625,8 +672,12 @@ class Markupper(object):
                         item = ""
                     except IndexError:
                         pass
-                    
-                table_contents[num_row].append({"tag":tag_mode,"item":item,"row":1,"col":1})
+
+                if re.search(r'^".*"$', item):
+                    item = re.search(r'^"(.*)"$', item).group(1)
+                    table_contents[num_row].append({"tag":"th","item":item,"row":1,"col":1})
+                else:
+                    table_contents[num_row].append({"tag":tag_mode,"item":item,"row":1,"col":1})
                 num_col = num_col + 1
             num_row = num_row + 1