diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 0da7ba49ed..3bc3424c39 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -104,7 +104,7 @@ class FB2MLizer(object): '\n\n
' % (author_first, author_middle, author_last, self.oeb_book.metadata.title[0].value, __appname__, __version__) - + def get_cover_page(self): output = u'' if 'titlepage' in self.oeb_book.guide: diff --git a/src/calibre/ebooks/fb2/output.py b/src/calibre/ebooks/fb2/output.py index fff08a0d60..67ea135c1b 100644 --- a/src/calibre/ebooks/fb2/output.py +++ b/src/calibre/ebooks/fb2/output.py @@ -18,8 +18,7 @@ class FB2Output(OutputFormatPlugin): options = set([ OptionRecommendation(name='inline_toc', recommended_value=False, level=OptionRecommendation.LOW, - help=_('Add Table of Contents to begenning of the book. Useful if ' - 'the book has its own table of contents.')), + help=_('Add Table of Contents to begenning of the book.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/ebooks/pdb/ereader/output.py b/src/calibre/ebooks/pdb/ereader/output.py deleted file mode 100644 index 7d3a75eeee..0000000000 --- a/src/calibre/ebooks/pdb/ereader/output.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- - -__license__ = 'GPL 3' -__copyright__ = '2009, John Schember ' -__docformat__ = 'restructuredtext en' - -import os - -from calibre.customize.conversion import OutputFormatPlugin -from calibre.ebooks.pdb.ereader.writer import Writer - -class EREADEROutput(OutputFormatPlugin): - - name = 'eReader PDB Output' - author = 'John Schember' - file_type = 'erpdb' - - def convert(self, oeb_book, output_path, input_plugin, opts, log): - writer = Writer(log) - - close = False - if not hasattr(output_path, 'write'): - close = True - if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '': - os.makedirs(os.path.dirname(output_path)) - out_stream = open(output_path, 'wb') - else: - out_stream = output_path - - out_stream.seek(0) - out_stream.truncate() - - writer.dump(oeb_book, out_stream) - - if close: - out_stream.close() - diff --git a/src/calibre/ebooks/pdb/output.py b/src/calibre/ebooks/pdb/output.py index b591769ec8..9a844d2136 100644 --- a/src/calibre/ebooks/pdb/output.py +++ b/src/calibre/ebooks/pdb/output.py @@ -27,6 +27,9 @@ class PDBOutput(OutputFormatPlugin): help=_('Specify the character encoding of the output document. ' \ 'The default is cp1252. Note: This option is not honored by all ' \ 'formats.')), + OptionRecommendation(name='inline_toc', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Add Table of Contents to begenning of the book.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py index ac66c9a9f5..970bcd3594 100644 --- a/src/calibre/ebooks/pml/output.py +++ b/src/calibre/ebooks/pml/output.py @@ -31,8 +31,10 @@ class PMLOutput(OutputFormatPlugin): OptionRecommendation(name='output_encoding', recommended_value='cp1252', level=OptionRecommendation.LOW, help=_('Specify the character encoding of the output document. ' \ - 'The default is cp1252. Note: This option is not honored by all ' \ - 'formats.')), + 'The default is cp1252.')), + OptionRecommendation(name='inline_toc', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Add Table of Contents to begenning of the book.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 59b27f1763..f441e20917 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -85,6 +85,15 @@ class PMLMLizer(object): def pmlmlize_spine(self): self.image_hrefs = {} self.link_hrefs = {} + output = u'' + output += self.get_cover_page() + output += u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk' + output += self.get_text() + output = output.replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc()) + output = self.clean_text(output) + return output + + def get_cover_page(self): output = u'' if 'titlepage' in self.oeb_book.guide: self.log.debug('Generating title page...') @@ -93,14 +102,28 @@ class PMLMLizer(object): if item.spine_position is None: stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile) output += self.dump_text(item.data.find(XHTML('body')), stylizer, item) + return output + + def get_toc(self): + toc = u'' + if self.opts.inline_toc: + self.log.debug('Generating table of contents...') + toc += u'\\X0%s\\X0\n\n' % _('Table of Contents:') + for item in self.oeb_book.toc: + if item.href in self.link_hrefs.keys(): + toc += '* \\q="#%s"%s\\q\n' % (self.link_hrefs[item.href], item.title) + else: + self.oeb.warn('Ignoring toc item: %s not found in document.' % item) + return toc + + def get_text(self): + text = u'' for item in self.oeb_book.spine: self.log.debug('Converting %s to PML markup...' % item.href) stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile) - output += self.add_page_anchor(item) - output += self.dump_text(item.data.find(XHTML('body')), stylizer, item) - output = self.clean_text(output) - - return output + text += self.add_page_anchor(item) + text += self.dump_text(item.data.find(XHTML('body')), stylizer, item) + return text def add_page_anchor(self, page): return self.get_anchor(page, '') diff --git a/src/calibre/ebooks/rb/output.py b/src/calibre/ebooks/rb/output.py index 04c7d41790..0e0bd27326 100644 --- a/src/calibre/ebooks/rb/output.py +++ b/src/calibre/ebooks/rb/output.py @@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en' import os -from calibre.customize.conversion import OutputFormatPlugin +from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation from calibre.ebooks.rb.writer import RBWriter class RBOutput(OutputFormatPlugin): @@ -15,6 +15,12 @@ class RBOutput(OutputFormatPlugin): author = 'John Schember' file_type = 'rb' + options = set([ + OptionRecommendation(name='inline_toc', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Add Table of Contents to begenning of the book.')), + ]) + def convert(self, oeb_book, output_path, input_plugin, opts, log): close = False if not hasattr(output_path, 'write'): diff --git a/src/calibre/ebooks/rb/rbml.py b/src/calibre/ebooks/rb/rbml.py index 2c4bb6916c..679ccaa39b 100644 --- a/src/calibre/ebooks/rb/rbml.py +++ b/src/calibre/ebooks/rb/rbml.py @@ -72,6 +72,16 @@ class RBMLizer(object): def mlize_spine(self): self.link_hrefs = {} output = u'' + output += self.get_cover_page() + output += u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk' + output += self.get_text() + output += u'' + output = output.replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc()) + output = self.clean_text(output) + return output + + def get_cover_page(self): + output = u'' if 'titlepage' in self.oeb_book.guide: self.log.debug('Generating cover page...') href = self.oeb_book.guide['titlepage'].href @@ -79,13 +89,28 @@ class RBMLizer(object): if item.spine_position is None: stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile) output += self.dump_text(item.data.find(XHTML('body')), stylizer, item) + return output + + def get_toc(self): + toc = u'' + if self.opts.inline_toc: + self.log.debug('Generating table of contents...') + toc += u'

%s

' + return toc + + def get_text(self): + output = u'' for item in self.oeb_book.spine: self.log.debug('Converting %s to RocketBook HTML...' % item.href) stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile) output += self.add_page_anchor(item) output += self.dump_text(item.data.find(XHTML('body')), stylizer, item) - output += u'' - output = self.clean_text(output) return output def add_page_anchor(self, page): diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index c13949af2e..38d1b3ebb7 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -30,7 +30,10 @@ class TXTOutput(OutputFormatPlugin): help=_('Specify the character encoding of the output document. ' \ 'The default is utf-8. Note: This option is not honored by all ' \ 'formats.')), - ]) + OptionRecommendation(name='inline_toc', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Add Table of Contents to begenning of the book.')), + ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): writer = TXTMLizer(log) diff --git a/src/calibre/ebooks/txt/txtml.py b/src/calibre/ebooks/txt/txtml.py index 94f2a181c5..24a9fb0878 100644 --- a/src/calibre/ebooks/txt/txtml.py +++ b/src/calibre/ebooks/txt/txtml.py @@ -44,6 +44,7 @@ class TXTMLizer(object): def mlize_spine(self): output = u'' + output += self.get_toc() for item in self.oeb_book.spine: self.log.debug('Converting %s to TXT...' % item.href) stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile) @@ -62,6 +63,15 @@ class TXTMLizer(object): return text + def get_toc(self): + toc = u'' + if getattr(self.opts, 'inline_toc', None): + self.log.debug('Generating table of contents...') + toc += u'%s\n\n' % _(u'Table of Contents:') + for item in self.oeb_book.toc: + toc += u'* %s\n\n' % item.title + return toc + def cleanup_text(self, text): self.log.debug('\tClean up text...') # Replace bad characters. diff --git a/src/calibre/gui2/convert/fb2_output.py b/src/calibre/gui2/convert/fb2_output.py new file mode 100644 index 0000000000..76d4c56af3 --- /dev/null +++ b/src/calibre/gui2/convert/fb2_output.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2.convert.fb2_output_ui import Ui_Form +from calibre.gui2.convert import Widget + +format_model = None + +class PluginWidget(Widget, Ui_Form): + + TITLE = _('FB2 Output') + HELP = _('Options specific to')+' FB2 '+_('output') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, 'fb2_output', ['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/fb2_output.ui b/src/calibre/gui2/convert/fb2_output.ui new file mode 100644 index 0000000000..007af454c4 --- /dev/null +++ b/src/calibre/gui2/convert/fb2_output.ui @@ -0,0 +1,41 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 246 + + + + + + + + &Inline TOC + + + + + + + + diff --git a/src/calibre/gui2/convert/pdb_output.py b/src/calibre/gui2/convert/pdb_output.py index 959078ad97..220311546c 100644 --- a/src/calibre/gui2/convert/pdb_output.py +++ b/src/calibre/gui2/convert/pdb_output.py @@ -17,7 +17,7 @@ class PluginWidget(Widget, Ui_Form): HELP = _('Options specific to')+' PDB '+_('output') def __init__(self, parent, get_option, get_help, db=None, book_id=None): - Widget.__init__(self, parent, 'pdb_output', ['format']) + Widget.__init__(self, parent, 'pdb_output', ['format', '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/pdb_output.ui b/src/calibre/gui2/convert/pdb_output.ui index 3d35a1f4e3..772a19b79e 100644 --- a/src/calibre/gui2/convert/pdb_output.ui +++ b/src/calibre/gui2/convert/pdb_output.ui @@ -27,7 +27,7 @@ - + Qt::Vertical @@ -40,6 +40,13 @@ + + + + &Inline TOC + + + diff --git a/src/calibre/gui2/convert/rb_output.py b/src/calibre/gui2/convert/rb_output.py new file mode 100644 index 0000000000..5fb214459f --- /dev/null +++ b/src/calibre/gui2/convert/rb_output.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2.convert.rb_output_ui import Ui_Form +from calibre.gui2.convert import Widget + +format_model = None + +class PluginWidget(Widget, Ui_Form): + + TITLE = _('RB Output') + HELP = _('Options specific to')+' RB '+_('output') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, 'rb_output', ['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/rb_output.ui b/src/calibre/gui2/convert/rb_output.ui new file mode 100644 index 0000000000..007af454c4 --- /dev/null +++ b/src/calibre/gui2/convert/rb_output.ui @@ -0,0 +1,41 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 246 + + + + + + + + &Inline TOC + + + + + + + + diff --git a/src/calibre/gui2/convert/txt_output.py b/src/calibre/gui2/convert/txt_output.py index b3a79e1326..407c308089 100644 --- a/src/calibre/gui2/convert/txt_output.py +++ b/src/calibre/gui2/convert/txt_output.py @@ -17,7 +17,7 @@ class PluginWidget(Widget, Ui_Form): HELP = _('Options specific to')+' TXT '+_('output') def __init__(self, parent, get_option, get_help, db=None, book_id=None): - Widget.__init__(self, parent, 'txt_output', ['newline']) + Widget.__init__(self, parent, 'txt_output', ['newline', '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 32b14b9bc4..6e62040533 100644 --- a/src/calibre/gui2/convert/txt_output.ui +++ b/src/calibre/gui2/convert/txt_output.ui @@ -27,7 +27,7 @@ - + Qt::Vertical @@ -40,6 +40,13 @@ + + + + &Inline TOC + + +