Commits

camlspotter committed 436f1d0

update

Comments (0)

Files changed (1)

extensions/hatenaWriter.py

 def isstring(s):
     return isinstance(s, unicode) or isinstance(s, str)
 
-class OneLineFailure(Exception):
+class InlineFailure(Exception):
     """hoge"""
 
-def one_line_failure():
-    raise OneLineFailure
+def inline_failure():
+    raise InlineFailure
 
 class Block():
     def __init__(self, parent):
     def to_string(self, indent):
         return '\n'.join([self.elem_to_string(indent, x) for x in self.contents])
 
-    def try_one_line_elem(self, elem): # string is special and thus stupid
+    def try_inline_elem(self, elem): # string is special and thus stupid
         if isstring(elem):
             return elem
         else:
-            return elem.try_one_line()
+            return elem.try_inline()
 
-    def try_one_line_internal(self):
-        return ' '.join([self.try_one_line_elem(elem) for elem in self.contents])
+    def try_inline_internal(self):
+        return ' '.join([self.try_inline_elem(elem) for elem in self.contents])
 
-    # may raise OneLineFailure
-    def try_one_line(self):
-        one_line_failure()
+    # may raise InlineFailure
+    def try_inline(self):
+        inline_failure()
         
 class Title(Block):
     def __init__(self, parent, level):
         self.level = level
 
     def to_string(self, indent):
-        return '*' * self.level + ' ' + Block.try_one_line_internal(self)
+        return '*' * self.level + ' ' + Block.try_inline_internal(self)
 
 class Par(Block):
     def __init__(self, parent):
 
     def to_string(self, indent):
         if self.is_first_item():
-            return Block.to_string(self, indent)
+            return 'P ' + Block.to_string(self, indent) + ' /P'
         else:
             return ' ' * indent + '<p>\n' + Block.to_string(self, indent)
 
-    def try_one_line(self):
+    def try_inline(self):
         if self.is_first_item():
-            return self.try_one_line_internal()
+            return self.try_inline_internal()
         else:
-            one_line_failure()
+            print "HOGE" + str(self.contents)
+            inline_failure()
 
 class HTML(Block):
     def __init__(self, parent, tag):
 
     def to_string(self, indent):
         try:
-            return ' ' * indent + '<' + self.tag() + '>' + self.try_one_line_internal() + '</' + self.tag() + '>'
-        except OneLineFailure:
+            return ' ' * indent + '<' + self.tag() + '>' + self.try_inline_internal() + '</' + self.tag() + '>'
+        except InlineFailure:
             return ' ' * indent + '<' + self.tag() + '>\n' + Block.to_string(self, indent+2) + '\n' + ' ' * indent + '</' + self.tag() + '>' 
 
 class LItem(HTML):
             self.end_block()
 
     def visit_target(self, node):
-        print "target " + repr(node)
-        self.new_block(Verbose, str(node))
+        self.new_block(Verbose, "target")
     def depart_target(self, node):
         pass
 
+#
 #    def visit_index(self, node):
 #        raise nodes.SkipNode
 #
 #    def depart_pending_xref(self, node):
 #        pass
 #
-#    def visit_reference(self, node):
-#        pass
-#    def depart_reference(self, node):
-#        pass
+    def visit_reference(self, node):
+        pass
+    def depart_reference(self, node):
+        pass
 
 #    def visit_download_reference(self, node):
 #        pass
 #    def depart_download_reference(self, node):
 #        pass
-#
+
     def visit_emphasis(self, node):
         self.add_text('<it>')
     def depart_emphasis(self, node):
 #        self.add_text('<SYSTEM MESSAGE: %s>' % node.astext())
 #        self.end_state()
 #        raise nodes.SkipNode
-#
-#    def visit_comment(self, node):
-#        raise nodes.SkipNode
-#
-#    def visit_meta(self, node):
-#        # only valid for HTML
-#        raise nodes.SkipNode
-#
+
+    def visit_comment(self, node):
+        raise nodes.SkipNode
+
+    def visit_meta(self, node):
+        # only valid for HTML
+        raise nodes.SkipNode
+
 #    def visit_raw(self, node):
 #        if 'text' in node.get('format', '').split():
 #            self.body.append(node.astext())