diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py index 3781a7f74a..493fdf3967 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): @@ -16,6 +16,13 @@ class TXTInput(InputFormatPlugin): description = 'Convert TXT files to HTML' file_types = set(['txt']) + options = set([ + OptionRecommendation(name='single_line_paras', recommended_value=False, + help=_('Normally calibre treats blank lines as paragraph markers. ' + 'With this option it will assume that every line represents ' + 'a paragraph instead.')), + ]) + def convert(self, stream, options, file_ext, log, accelerators): ienc = stream.encoding if stream.encoding else 'utf-8' @@ -24,6 +31,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) diff --git a/src/calibre/gui2/convert/txt_input.py b/src/calibre/gui2/convert/txt_input.py new file mode 100644 index 0000000000..71dbbe1fe2 --- /dev/null +++ b/src/calibre/gui2/convert/txt_input.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2.convert.txt_input_ui import Ui_Form +from calibre.gui2.convert import Widget + +class PluginWidget(Widget, Ui_Form): + + TITLE = _('TXT Input') + HELP = _('Options specific to')+' TXT '+_('input') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, 'txt_input', + ['single_line_paras']) + self.db, self.book_id = db, book_id + self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/txt_input.ui b/src/calibre/gui2/convert/txt_input.ui new file mode 100644 index 0000000000..191e749833 --- /dev/null +++ b/src/calibre/gui2/convert/txt_input.ui @@ -0,0 +1,41 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 213 + + + + + + + + Treat each &line as a paragraph + + + + + + + +