From 9f453fa65e7b6dc7e29a04c91544dd59e63b3a36 Mon Sep 17 00:00:00 2001 From: Li Fanxi Date: Mon, 18 Oct 2010 16:12:19 +0800 Subject: [PATCH] [Options] Add three basic options to SNBOutput plugin. --- src/calibre/ebooks/snb/output.py | 26 ++++---- src/calibre/ebooks/snb/snbml.py | 25 ++++++-- src/calibre/gui2/convert/snb_output.py | 14 +--- src/calibre/gui2/convert/snb_output.ui | 89 ++++++++++---------------- 4 files changed, 68 insertions(+), 86 deletions(-) diff --git a/src/calibre/ebooks/snb/output.py b/src/calibre/ebooks/snb/output.py index 549ee51446..619fff1ee2 100644 --- a/src/calibre/ebooks/snb/output.py +++ b/src/calibre/ebooks/snb/output.py @@ -20,20 +20,10 @@ class SNBOutput(OutputFormatPlugin): file_type = 'snb' options = set([ - # OptionRecommendation(name='newline', recommended_value='system', - # level=OptionRecommendation.LOW, - # short_switch='n', choices=TxtNewlines.NEWLINE_TYPES.keys(), - # help=_('Type of newline to use. Options are %s. Default is \'system\'. ' - # 'Use \'old_mac\' for compatibility with Mac OS 9 and earlier. ' - # 'For Mac OS X use \'unix\'. \'system\' will default to the newline ' - # 'type used by this OS.') % sorted(TxtNewlines.NEWLINE_TYPES.keys())), OptionRecommendation(name='snb_output_encoding', recommended_value='utf-8', level=OptionRecommendation.LOW, help=_('Specify the character encoding of the output document. ' \ 'The default is utf-8.')), - # OptionRecommendation(name='inline_toc', - # recommended_value=False, level=OptionRecommendation.LOW, - # help=_('Add Table of Contents to beginning of the book.')), OptionRecommendation(name='snb_max_line_length', recommended_value=0, level=OptionRecommendation.LOW, help=_('The maximum number of characters per line. This splits on ' @@ -41,10 +31,18 @@ class SNBOutput(OutputFormatPlugin): 'the line will be broken at the space after and will exceed the ' 'specified value. Also, there is a minimum of 25 characters. ' 'Use 0 to disable line splitting.')), - # OptionRecommendation(name='force_max_line_length', - # 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='insert_empty_line', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Speicfy whether or not to insert an empty line between ' + 'two paragraphs.')), + OptionRecommendation(name='indent_first_line', + recommended_value=True, level=OptionRecommendation.LOW, + help=_('Speicfy whether or not to insert two space characters ' + 'to indent the first line of each paragraph.')), + OptionRecommendation(name='hide_chapter_name', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Speicfy whether or not to hide the chapter title for each ' + 'chapter. Useful for image-only output (eg. comics).')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/ebooks/snb/snbml.py b/src/calibre/ebooks/snb/snbml.py index e3eed5a476..d84ce95250 100644 --- a/src/calibre/ebooks/snb/snbml.py +++ b/src/calibre/ebooks/snb/snbml.py @@ -88,7 +88,10 @@ class SNBMLizer(object): trees = { } for subitem, subtitle in self.subitems: snbcTree = etree.Element("snbc") - etree.SubElement(etree.SubElement(snbcTree, "head"), "title").text = subtitle + snbcHead = etree.SubElement(snbcTree, "head") + etree.SubElement(snbcHead, "title").text = subtitle + if self.opts and self.opts.hide_chapter_name: + etree.SubElement(snbcHead, "hidetitle").text = u"true" etree.SubElement(snbcTree, "body") trees[subitem] = snbcTree output.append(u'%s%s\n\n' % (CALIBRE_SNB_BM_TAG, "")) @@ -96,27 +99,37 @@ class SNBMLizer(object): output = self.cleanup_text(u''.join(output)) subitem = '' + bodyTree = trees[subitem].find(".//body") for line in output.splitlines(): if not line.find(CALIBRE_SNB_PRE_TAG) == 0: line = line.strip(u' \t\n\r\u3000') else: - etree.SubElement(trees[subitem].find(".//body"), "text").text = \ + etree.SubElement(bodyTree, "text").text = \ etree.CDATA(line[len(CALIBRE_SNB_PRE_TAG):]) continue if len(line) != 0: if line.find(CALIBRE_SNB_IMG_TAG) == 0: prefix = ProcessFileName(os.path.dirname(self.item.href)) if prefix != '': - etree.SubElement(trees[subitem].find(".//body"), "img").text = \ + etree.SubElement(bodyTree, "img").text = \ prefix + '_' + line[len(CALIBRE_SNB_IMG_TAG):] else: - etree.SubElement(trees[subitem].find(".//body"), "img").text = \ + etree.SubElement(bodyTree, "img").text = \ line[len(CALIBRE_SNB_IMG_TAG):] elif line.find(CALIBRE_SNB_BM_TAG) == 0: subitem = line[len(CALIBRE_SNB_BM_TAG):] + bodyTree = trees[subitem].find(".//body") else: - etree.SubElement(trees[subitem].find(".//body"), "text").text = \ - etree.CDATA(unicode(u'\u3000\u3000' + line)) + if self.opts and self.opts.indent_first_line: + prefix = u'\u3000\u3000' + else: + prefix = u'' + etree.SubElement(bodyTree, "text").text = \ + etree.CDATA(unicode(prefix + line)) + if self.opts and self.opts.insert_empty_line: + etree.SubElement(bodyTree, "text").text = \ + etree.CDATA(u'') + return trees def remove_newlines(self, text): diff --git a/src/calibre/gui2/convert/snb_output.py b/src/calibre/gui2/convert/snb_output.py index b3ebfc747f..3f3ee8f8c9 100644 --- a/src/calibre/gui2/convert/snb_output.py +++ b/src/calibre/gui2/convert/snb_output.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- __license__ = 'GPL 3' -__copyright__ = '2009, John Schember ' +__copyright__ = '2010, Li Fanxi ' __docformat__ = 'restructuredtext en' from calibre.gui2.convert.snb_output_ui import Ui_Form @@ -18,18 +18,8 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, - []) + ['insert_empty_line', 'indent_first_line', 'hide_chapter_name',]) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) - # default = self.opt_newline.currentText() - # global newline_model - # if newline_model is None: - # newline_model = BasicComboModel(TxtNewlines.NEWLINE_TYPES.keys()) - # self.newline_model = newline_model - # self.opt_newline.setModel(self.newline_model) - - # default_index = self.opt_newline.findText(default) - # system_index = self.opt_newline.findText('system') - # self.opt_newline.setCurrentIndex(default_index if default_index != -1 else system_index if system_index != -1 else 0) diff --git a/src/calibre/gui2/convert/snb_output.ui b/src/calibre/gui2/convert/snb_output.ui index a5ff8ce7ef..21e67bfb4c 100644 --- a/src/calibre/gui2/convert/snb_output.ui +++ b/src/calibre/gui2/convert/snb_output.ui @@ -13,60 +13,41 @@ Form - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Hide chapter name + + + + + + + Insert space before the first line for each paragraph + + + + + + + Insert empty line between paragraphs + + +