OSDN Git Service

html parser strips spaser if it is first character of a line.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 10 Apr 2009 19:04:57 +0000 (04:04 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 10 Apr 2009 19:04:57 +0000 (04:04 +0900)
src/FukuiNoNamari/barehtmlparser.py

index 94bb8be..f299d45 100644 (file)
@@ -41,16 +41,19 @@ class BareHTMLParser(HTMLParserEx):
         self.bold = False
         self.href = None
         self.buffer = ""
+        self.line_empty = True
 
     def reset_func(self, to_out_func):
         self.flush()
         self.to_out_func = to_out_func
 
     def to_out(self, data):
-        n = len(self.buffer)
-        if n == 0:
+        # n = len(self.buffer)
+        # if n == 0:
+        if self.line_empty:
             data = data.lstrip(" ")
         self.buffer = self.buffer + data
+        self.line_empty = False
 
     def flush(self):
         if self.buffer:
@@ -60,6 +63,7 @@ class BareHTMLParser(HTMLParserEx):
     def newline(self):
         self.buffer = self.buffer.rstrip(" ")
         self.flush()
+        self.line_empty = True
         self.on_new_line()
 
     # override