diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index fa9329fc40..5717e79b24 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -20,7 +20,9 @@ from calibre.utils.imghdr import what def sanitize_file_name(x): - return re.sub(r'[?&=;#]', '_', ascii_filename(x)) + ans = re.sub(r'\s+', ' ', re.sub(r'[?&=;#]', '_', ascii_filename(x))).strip().rstrip('.') + ans, ext = ans.rpartition('.')[::2] + return ans.strip() + '.' + ext.strip() class HTMLInput(InputFormatPlugin):