changeset 5651:14fd7e416807

Get rid of the empty line at the end of code highlights
author Radomir Dopieralski <moindev@sheep.art.pl>
date Mon, 05 Apr 2010 16:21:23 +0200
parents 90cca4781e96
children 5b04b7edee94 b82318102f22
files MoinMoin/parser/highlight.py
diffstat 1 files changed, 21 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/highlight.py	Mon Apr 05 01:16:58 2010 +0200
+++ b/MoinMoin/parser/highlight.py	Mon Apr 05 16:21:23 2010 +0200
@@ -95,34 +95,33 @@
             # ... or use the token's name when nothing apropriate
             # return str(ttype).replace(".", " ")
 
-    def format(self, tokensource, outfile):
-        line_ready = False
+    def add_next_line(self, line_parts):
         fmt = self.formatter
-        result = self.result
+        self.lineno += 1
+        self.result.append(fmt.code_line(1))
+        self.result.append(fmt.line_anchordef(self.lineno))
+        self.result += line_parts
+        self.result.append(fmt.code_line(0))
+
+    def format(self, tokensource, outfile):
+        fmt = self.formatter    
         self.lineno = self.start_line
-
+        line_parts = []
         for ttype, value in tokensource:
             class_ = self.get_class(ttype)
             if value:
                 for line in self.line_re.split(value):
-                    if not line_ready:
-                        self.lineno += 1
-                        result.append(fmt.code_line(1))
-                        result.append(fmt.line_anchordef(self.lineno))
-                        line_ready = True
                     if line == '\n':
-                        result.append(fmt.code_line(0))
-                        line_ready = False
-                    else:
-                        if class_:
-                            result.append(fmt.code_token(1, class_))
-                        result.append(fmt.text(line))
-                        if class_:
-                            result.append(fmt.code_token(0, class_))
-        result[-2] = ''
-        result[-1] = ''
-#        if line_ready:
-#            result.append(fmt.code_line(0))
+                        self.add_next_line(line_parts)
+                        line_parts = []
+                        continue
+                    if class_:
+                        line_parts.append(fmt.code_token(1, class_))
+                    line_parts.append(fmt.text(line))
+                    if class_:
+                        line_parts.append(fmt.code_token(0, class_))
+        if line_parts and line_parts != [u'']: # Don't output an empty line at the end.
+            self.add_next_line(line_parts)            
 
 
 class Parser:
@@ -132,7 +131,7 @@
 
     def __init__(self, raw, request, filename=None, format_args='', **kw):
         self.request = request
-        self.raw = raw.strip('\n')
+        self.raw = raw
         self.filename = filename
         self.start_line = kw.get('start_line', 0)