Commits

Anonymous committed 0c17d0a

don't add space before closing quote
strip spaces at end of line
don't add newlines just before eof

  • Participants
  • Parent commits 8ca0528

Comments (0)

Files changed (1)

         quote_stack = []
         self.edited_text = u''
         for i, token in enumerate(self._tokens[:-1]):
+            next_token = self._tokens[i + 1]
+
             # if we have a paragraph break, insert that and go on to
             # next token
             if token.is_para:
-                self.edited_text += u'\n\n'
+                if not next_token.is_eof:
+                    self.edited_text = self.edited_text.rstrip() + u'\n\n'
                 continue
             # skip non-printing tokens
             if token.non_printing:
 
             # now figure out how many spaces should follow it
             append_space = ' '
-            next_token = self._tokens[i + 1]
 
             if (token.is_open or
                 token.is_currency_symbol or
                 next_token.is_nonspacing_punc or
                 next_token.is_eof):
                     append_space = ''
+            elif (next_token.is_quote and
+                  quote_stack and
+                  quote_stack[-1] == next_token.str):
+                # no space before close quote
+                append_space = ''
             elif token.str == '.':
-                append_space = '  '
+                if not next_token.is_eof:
+                    append_space = '  '
             elif token.is_quote:
                 if quote_stack and quote_stack[-1] == token.str:
                     # space after close quote