From 4225ab51a56ab19ee634e07d5676b1a2823e8223 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Mar 2022 10:55:41 +0530 Subject: [PATCH] TXT Input: Speed up removal of leading whitespace. Fixes #1965443 ["Remove indents at beginning of lines" sometimes greatly slow down conversion](https://bugs.launchpad.net/calibre/+bug/1965443) --- 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 be017b3f4f..65a97dba4d 100644 --- a/src/calibre/ebooks/txt/processor.py +++ b/src/calibre/ebooks/txt/processor.py @@ -220,7 +220,7 @@ def remove_indents(txt): ''' Remove whitespace at the beginning of each line. ''' - return '\n'.join(l.lstrip() for l in txt.splitlines()) + return re.sub(r'^\s+', '', txt, flags=re.MULTILINE) def opf_writer(path, opf_name, manifest, spine, mi):