OSDN Git Service

change fig command to not use hash.
authorhylom <hylom@users.sourceforge.jp>
Wed, 13 May 2009 07:30:11 +0000 (16:30 +0900)
committerhylom <hylom@users.sourceforge.jp>
Wed, 13 May 2009 07:30:11 +0000 (16:30 +0900)
markupper.py

index 9e4f9fc..2d9b5ee 100755 (executable)
@@ -61,7 +61,7 @@ class Markupper(object):
     def index_haskey(self, key):
         return self._index.has_key(key)
 
-    def markup(self, input_iter):
+    def markup(self, input_iter, release="0"):
         """
         Do markup.
 
@@ -73,6 +73,7 @@ class Markupper(object):
         # alist = ["a", "a:href", "a:name", "b", "br" ]
         # dlist = ["*"]
         # tag_filter = HTMLTagFilter.HTMLTagFilter(HTMLTagFilter.DENY_ALLOW, alist, dlist)
+        self._release = release
 
         self.index_add("figs", [])
 
@@ -325,6 +326,51 @@ class Markupper(object):
     """ % (cap)
 
     def _fig(self, line):
+        if self._release == 1:
+            self._fig_release(line)
+        else:
+            self._fig(line)
+
+
+    def _fig(self, line):
+        try:
+            str_title = re.search(ur"^☆(図.*)$", line).group(1)
+        except AttributeError:
+            str_title = ""
+        print self._fig_start()
+
+        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_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", match_o1.group(1))
+        elif not match_o2 == None:
+            imgname = match_o1.group(1)
+            imgname_s = match_o1.group(2)
+
+        if not os.path.isfile(imgname_s):
+            imgname_s = imgname
+
+        print """<a href="%s">
+     <img src="%s" alt="%s">
+</a>
+     """ % (imgname, imgname_s, str_title)
+        
+
+        dic = self.index("figs")
+        dic.append(imgname)
+        if imgname_s != "":
+            dic.append(imgname_s)
+
+        print self._fig_end(str_title);
+
+
+    def _fig_release(self, line):
         try:
             str_title = re.search(ur"^☆(図.*)$", line).group(1)
         except AttributeError:
@@ -352,10 +398,10 @@ class Markupper(object):
             hash_s = hash
 
         print """<a href="/blob.pl?id=%s">
-    <slash type="image" id="%s" title="%s">
-    </a>
-    """ % (hash, hash_s, str_title)
-
+     <slash type="image" id="%s" title="%s">
+     </a>
+     """ % (hash, hash_s, str_title)
+        
 
         dic = self.index("figs")
         dic.append(imgname)