From a7fe4ea5ed6254bf4832d2a506934b16a294936a Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 27 Jan 2011 20:24:12 -0500 Subject: [PATCH] TXT Input: Make preserve_spaces fast and only use   when necessary. --- src/calibre/ebooks/txt/processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/txt/processor.py b/src/calibre/ebooks/txt/processor.py index 206a18b3e4..546d3f1842 100644 --- a/src/calibre/ebooks/txt/processor.py +++ b/src/calibre/ebooks/txt/processor.py @@ -103,7 +103,7 @@ def separate_paragraphs_print_formatted(txt): return txt def preserve_spaces(txt): - txt = txt.replace(' ', ' ') + txt = re.sub('(?P[ ]{2,})', lambda mo: ' ' + (' ' * (len(mo.group('space')) - 1)), txt) txt = txt.replace('\t', '    ') return txt