From 072974bedfd17a5ec9e1e601d778c1a69f47511d Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 10 Aug 2009 06:57:23 -0400 Subject: [PATCH 1/2] Fix bug #3084: text input handle single line paragraphs. --- src/calibre/ebooks/txt/input.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py index 3781a7f74a..e9a1b072a9 100644 --- a/src/calibre/ebooks/txt/input.py +++ b/src/calibre/ebooks/txt/input.py @@ -16,6 +16,11 @@ class TXTInput(InputFormatPlugin): description = 'Convert TXT files to HTML' file_types = set(['txt']) + options = set([ + OptionRecommendation(name='single_line_paras', recommended_value=False, + help=_('Each line is a paragraph.')), + ]) + def convert(self, stream, options, file_ext, log, accelerators): ienc = stream.encoding if stream.encoding else 'utf-8' @@ -24,6 +29,11 @@ class TXTInput(InputFormatPlugin): log.debug('Reading text from file...') txt = stream.read().decode(ienc, 'replace') + if options.single_line_paras: + txt = txt.replace('\r\n', '\n') + txt = txt.replace('\r', '\n') + txt = txt.replace('\n', '\n\n') + log.debug('Running text though markdown conversion...') try: html = txt_to_markdown(txt) From 57ace85d3f90d4102ad2236ed8b7984268681917 Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 10 Aug 2009 07:04:37 -0400 Subject: [PATCH 2/2] Add missing import. TXT input options in gui. --- src/calibre/ebooks/txt/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py index e9a1b072a9..125d38ef25 100644 --- a/src/calibre/ebooks/txt/input.py +++ b/src/calibre/ebooks/txt/input.py @@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en' import os -from calibre.customize.conversion import InputFormatPlugin +from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation from calibre.ebooks.txt.processor import txt_to_markdown class TXTInput(InputFormatPlugin):