From e3823faad40e0566d4d1cf36b60590afe395aabc Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 16:04:06 -0500 Subject: [PATCH 1/7] Remove TXT specific options for indent and flush paragraphs, use the look and feel remove paragraph spacing option instead. --- src/calibre/ebooks/pdb/output.py | 2 -- src/calibre/ebooks/txt/output.py | 6 ------ src/calibre/ebooks/txt/txtml.py | 8 +++----- src/calibre/gui2/convert/txt_output.py | 2 +- src/calibre/gui2/convert/txt_output.ui | 16 +--------------- 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/calibre/ebooks/pdb/output.py b/src/calibre/ebooks/pdb/output.py index 3b4065213e..4e76a2d298 100644 --- a/src/calibre/ebooks/pdb/output.py +++ b/src/calibre/ebooks/pdb/output.py @@ -47,10 +47,8 @@ class PDBOutput(OutputFormatPlugin): if Writer is None: raise PDBError('No writer available for format %s.' % format) - setattr(opts, 'flush_paras', False) setattr(opts, 'max_line_length', 0) setattr(opts, 'force_max_line_length', False) - setattr(opts, 'indent_paras', False) writer = Writer(opts, log) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index 32bde90fe8..15db4b1974 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -33,9 +33,6 @@ class TXTOutput(OutputFormatPlugin): OptionRecommendation(name='inline_toc', recommended_value=False, level=OptionRecommendation.LOW, help=_('Add Table of Contents to beginning of the book.')), - OptionRecommendation(name='flush_paras', - recommended_value=False, level=OptionRecommendation.LOW, - help=_('Do not add a blank line between paragraphs.')), OptionRecommendation(name='max_line_length', recommended_value=0, level=OptionRecommendation.LOW, help=_('The maximum number of characters per line. This splits on ' @@ -47,9 +44,6 @@ class TXTOutput(OutputFormatPlugin): recommended_value=False, level=OptionRecommendation.LOW, help=_('Force splitting on the max-line-length value when no space ' 'is present. Also allows max-line-length to be below the minimum')), - OptionRecommendation(name='indent_paras', - recommended_value=False, level=OptionRecommendation.LOW, - help=_('Add a tab at the beginning of each paragraph.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/ebooks/txt/txtml.py b/src/calibre/ebooks/txt/txtml.py index 45383675b4..0f9700a124 100644 --- a/src/calibre/ebooks/txt/txtml.py +++ b/src/calibre/ebooks/txt/txtml.py @@ -98,18 +98,16 @@ class TXTMLizer(object): # Remove excessive newlines. text = re.sub('\n[ ]+\n', '\n\n', text) - if self.opts.flush_paras: + if self.opts.remove_paragraph_spacing: text = re.sub('\n{2,}', '\n', text) + text = re.sub('(?imu)^(?=.)', '\t', text) else: - text = re.sub('\n{3,}', '\n\n', text) + text = re.sub('\n{4,}', '\n\n\n', text) # Replace spaces at the beginning and end of lines text = re.sub('(?imu)^[ ]+', '', text) text = re.sub('(?imu)[ ]+$', '', text) - if self.opts.indent_paras: - text = re.sub('(?imu)^(?=.)', '\t', text) - if self.opts.max_line_length: max_length = self.opts.max_line_length if self.opts.max_line_length < 25 and not self.opts.force_max_line_length: diff --git a/src/calibre/gui2/convert/txt_output.py b/src/calibre/gui2/convert/txt_output.py index 2fc7f19908..b79cd5779c 100644 --- a/src/calibre/gui2/convert/txt_output.py +++ b/src/calibre/gui2/convert/txt_output.py @@ -19,7 +19,7 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, 'txt_output', ['newline', 'max_line_length', 'force_max_line_length', - 'inline_toc', 'flush_paras', 'indent_paras']) + 'inline_toc']) 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_output.ui b/src/calibre/gui2/convert/txt_output.ui index 8e5429b0ce..11a38690b1 100644 --- a/src/calibre/gui2/convert/txt_output.ui +++ b/src/calibre/gui2/convert/txt_output.ui @@ -27,7 +27,7 @@ - + Qt::Vertical @@ -47,20 +47,6 @@ - - - - Do not add a blank line between paragraphs. - - - - - - - Add a tab at the beginning of each paragraph - - - From 67ae787d45af75c50be66945426d19785338cc36 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 16:20:17 -0500 Subject: [PATCH 2/7] Revert PML indent changes. PML Output: Cleaner handling of paragraph indentation. --- src/calibre/ebooks/pml/pmlconverter.py | 4 ++-- src/calibre/ebooks/pml/pmlml.py | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index 099a23c544..3484be5927 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -71,8 +71,8 @@ class PML_HTMLizer(object): 'ra': ('', ''), 'c': ('
', '
'), 'r': ('
', '
'), - 't': ('
', '
'), - 'T': ('
', '
'), + 't': ('
', '
'), + 'T': ('
', '
'), 'i': ('', ''), 'u': ('', ''), 'd': ('', ''), diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 2e00ad6ae3..4310fb39ad 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -182,9 +182,14 @@ class PMLMLizer(object): # Remove excessive spaces text = re.sub('[ ]{2,}', ' ', text) - # Remove excessive newlines + # Remove excessive newlines. text = re.sub('\n[ ]+\n', '\n\n', text) - text = re.sub('\n\n\n+', '\n\n', text) + if self.opts.remove_paragraph_spacing: + text = re.sub('\n{2,}', '\n', text) + text = re.sub('(?imu)^(?P.+)$', lambda mo: mo.group('text') if re.search(r'\\[XxCm]', mo.group('text')) else ' %s' % mo.group('text'), text) + else: + text = re.sub('\n{4,}', '\n\n\n', text) + return text @@ -204,12 +209,10 @@ class PMLMLizer(object): tag_count = 0 # Are we in a paragraph block? - if tag in BLOCK_TAGS:# or style['display'] in BLOCK_STYLES: + if tag in BLOCK_TAGS: # or style['display'] in BLOCK_STYLES: if 'block' not in tag_stack: tag_count += 1 tag_stack.append('block') - if self.opts.remove_paragraph_spacing: - text.append('\\t') # Process tags that need special processing and that do not have inner # text. Usually these require an argument @@ -289,14 +292,10 @@ class PMLMLizer(object): close_tag_list.insert(0, tag_stack.pop()) text += self.close_tags(close_tag_list) if tag in SEPARATE_TAGS: - text.append('\n') - if not self.opts.remove_paragraph_spacing: - text.append('\n') + text.append('\n\n') - if 'block' not in tag_stack and text and text[-1] != '\n': - text.append('\n') - if not self.opts.remove_paragraph_spacing: - text.append('\n') + if 'block' not in tag_stack: + text.append('\n\n') #if style['page-break-after'] == 'always': # text.append('\\p') From c007eb5000719adac5b8335724726cd09e82a119 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 20:25:41 -0500 Subject: [PATCH 3/7] USBMS: Add filename to News and / special tags. --- src/calibre/devices/usbms/device.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 5d09d3821f..c56e0c0025 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -870,6 +870,7 @@ class Device(DeviceConfig, DevicePlugin): if special_tag is None: from calibre.library.save_to_disk import get_components extra_components = get_components(template, mdata, fname) + extra_components[-1] += ext else: tag = special_tag if tag.startswith(_('News')): @@ -883,17 +884,14 @@ class Device(DeviceConfig, DevicePlugin): c = sanitize(c) if not c: continue extra_components.append(c) - + extra_componets.append(fname) if not use_subdirs: extra_components = extra_components[:1] if not extra_components: fname = sanitize(self.filename_callback(fname, mdata)) - extra_components.append(fname) - extra_components = [str(x) for x in extra_components] - else: - extra_components[-1] += ext + extra_components.append(str(fname)) def remove_trailing_periods(x): ans = x From 081bb9b3ba15a80f06705b3666721543f6cd711f Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 20:30:42 -0500 Subject: [PATCH 4/7] USBMS: Use filename_callback on the filename with template and tags. --- src/calibre/devices/usbms/device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index c56e0c0025..9018879f83 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -870,7 +870,7 @@ class Device(DeviceConfig, DevicePlugin): if special_tag is None: from calibre.library.save_to_disk import get_components extra_components = get_components(template, mdata, fname) - extra_components[-1] += ext + extra_components[-1] = extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata))) else: tag = special_tag if tag.startswith(_('News')): @@ -884,7 +884,7 @@ class Device(DeviceConfig, DevicePlugin): c = sanitize(c) if not c: continue extra_components.append(c) - extra_componets.append(fname) + extra_componets.append(sanitize(self.filename_callback(fname, mdata))) if not use_subdirs: extra_components = extra_components[:1] From 78e350c6650f27589af01d855d4f5d7af341fce4 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 20:31:19 -0500 Subject: [PATCH 5/7] ... --- src/calibre/devices/usbms/device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 9018879f83..4bfb2c9e2a 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -870,7 +870,7 @@ class Device(DeviceConfig, DevicePlugin): if special_tag is None: from calibre.library.save_to_disk import get_components extra_components = get_components(template, mdata, fname) - extra_components[-1] = extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata))) + extra_components[-1] = extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata)) else: tag = special_tag if tag.startswith(_('News')): From b7022494cc27570b9320a3ea8d14797b083fbde6 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 20:31:53 -0500 Subject: [PATCH 6/7] ... --- src/calibre/devices/usbms/device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 4bfb2c9e2a..19b98f64aa 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -884,7 +884,7 @@ class Device(DeviceConfig, DevicePlugin): c = sanitize(c) if not c: continue extra_components.append(c) - extra_componets.append(sanitize(self.filename_callback(fname, mdata))) + extra_components.append(sanitize(self.filename_callback(fname, mdata))) if not use_subdirs: extra_components = extra_components[:1] From 77e832d4a43db34b4e71971595bc331d254c9aad Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 1 Jan 2010 20:38:53 -0500 Subject: [PATCH 7/7] News and / tag use name from template for filename. --- src/calibre/devices/usbms/device.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 19b98f64aa..2e67a3098d 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -867,27 +867,25 @@ class Device(DeviceConfig, DevicePlugin): fname = sanitize(fname) ext = os.path.splitext(fname)[1] - if special_tag is None: - from calibre.library.save_to_disk import get_components - extra_components = get_components(template, mdata, fname) - extra_components[-1] = extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata)) - else: + from calibre.library.save_to_disk import get_components + extra_components = get_components(template, mdata, fname) + extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata)) + + if special_tag: + name = extra_components[-1] + extra_components = [] tag = special_tag if tag.startswith(_('News')): extra_components.append('News') - c = sanitize(mdata.title if mdata.title else '') - #c = c.split('[')[0].strip() - if c: - extra_components.append(c) else: for c in tag.split('/'): c = sanitize(c) if not c: continue extra_components.append(c) - extra_components.append(sanitize(self.filename_callback(fname, mdata))) + extra_components.append(name) if not use_subdirs: - extra_components = extra_components[:1] + extra_components = extra_components[-1:] if not extra_components: fname = sanitize(self.filename_callback(fname, mdata))