OSDN Git Service

copy to mac os x environment.
[otptools/otptools.git] / markupper.py
old mode 100755 (executable)
new mode 100644 (file)
index 945e8d3..d4ad433
@@ -72,6 +72,7 @@ class Markupper(object):
         """
         self.input_iter = input_iter
         self._page_counter = 1
+        self._image_border = 0
         # alist = ["a", "a:href", "a:name", "b", "br" ]
         # dlist = ["*"]
         # tag_filter = HTMLTagFilter.HTMLTagFilter(HTMLTagFilter.DENY_ALLOW, alist, dlist)
@@ -89,6 +90,9 @@ class Markupper(object):
             elif re.search(ur"^☆image_dir:", line):
                 self._image_dir = re.search(ur"^☆image_dir:\s*(.*)$", line).group(1)
                 continue
+            elif re.search(ur"^☆image_border:\s(on|On|ON)", line):
+                self._image_border = 1
+                continue
             elif re.search(ur"^☆comment\s{{{$", line):
                 self._comment(line)
                 continue
@@ -134,6 +138,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
@@ -248,7 +255,7 @@ class Markupper(object):
         pass
 
     def _escape(self, line):
-        line = re.sub(ur"&", ur"&amp", line)
+        line = re.sub(ur"&", ur"&", line)
         line = re.sub(ur"<", ur"&lt;", line)
         line = re.sub(ur">", ur"&gt;", line)
         return line
@@ -267,6 +274,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)
@@ -335,6 +343,8 @@ class Markupper(object):
         for line in self.input_iter:
             line = line.strip("\n\r")
             line = self._escape(line)
+            line = line = re.sub(ur"[★*]b\[(.*?)]", ur"<b>\1</b>", line)
+            line = line = re.sub(ur"[★*]b{(.*?)}", ur"<b>\1</b>", line)
             if re.search(ur"""^☆\+---""", line):
                 break
             print line
@@ -439,12 +449,6 @@ class Markupper(object):
     </table>
     """ % (cap)
 
-    def _fig(self, line):
-        if self._release == 1:
-            self._fig_release(line)
-        else:
-            self._fig(line)
-
     def _get_png_geom(self, filepath):
         desc = deterfile.file(filepath)
         try:
@@ -486,6 +490,51 @@ class Markupper(object):
             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 _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:
@@ -513,10 +562,13 @@ class Markupper(object):
 
         alt = re.sub(r"""<[A-Za-z0-9!/]+.*?>""", "", alt)
 
-        return """<a href="%s">
+        ret = """<a href="%s">
   <img src="%s" alt="%s">
 </a>
 """ % (file, file_s, alt)
+
+
+        return ret
         
 
     def _fig_release(self, line):
@@ -561,7 +613,7 @@ class Markupper(object):
 
 
     def _table_start(self, cap):
-        return """<div style="width:90%%; margin-left:auto;margin-right:auto;"><table align="center" border="1" class="table">
+        return """<div style="width:90%%; margin-left:auto;margin-right:auto;"><table align="center" border="1" class="table" width="100%%">
     <caption><b>%s</b></caption>
     """ % cap
 
@@ -595,7 +647,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"
@@ -621,8 +672,21 @@ class Markupper(object):
                             table_contents[num_row][num_col-n]["col"] += 1
                         except IndexError:
                             pass
-
-                table_contents[num_row].append({"tag":tag_mode,"item":item,"row":1,"col":1})
+                if item == u"↓":
+                    n = 1
+                    try:
+                        while table_contents[num_row-n][num_col]["item"] == "":
+                            n += 1
+                        table_contents[num_row-n][num_col]["row"] += 1
+                        item = ""
+                    except IndexError:
+                        pass
+
+                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