From a37fe4b71793185d8e296f5491065db7f42377a4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 30 Mar 2014 21:32:09 +0530 Subject: [PATCH] Get rid of the option to control index generation Index will be generated automatically, wherever the INDEX field exists in the input docx file. --- .../ebooks/conversion/plugins/docx_input.py | 6 +----- src/calibre/ebooks/docx/index.py | 1 + src/calibre/ebooks/docx/to_html.py | 14 +++++--------- src/calibre/gui2/convert/docx_input.py | 2 +- src/calibre/gui2/convert/docx_input.ui | 7 ------- 5 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/docx_input.py b/src/calibre/ebooks/conversion/plugins/docx_input.py index fe987ea28f..a998fd4678 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_input.py +++ b/src/calibre/ebooks/conversion/plugins/docx_input.py @@ -19,15 +19,11 @@ class DOCXInput(InputFormatPlugin): help=_('Normally, if a large image is present at the start of the document that looks like a cover, ' 'it will be removed from the document and used as the cover for created ebook. This option ' 'turns off that behavior.')), - OptionRecommendation(name='docx_index', recommended_value=False, - help=_('If there are embedded index markers in the document, this option will use them to create ' - 'an alphabetical index with links to the locations of the markers.')), - } recommendations = set([('page_breaks_before', '/', OptionRecommendation.MED)]) def convert(self, stream, options, file_ext, log, accelerators): from calibre.ebooks.docx.to_html import Convert - return Convert(stream, detect_cover=not options.docx_no_cover, do_index=options.docx_index, log=log)() + return Convert(stream, detect_cover=not options.docx_no_cover, log=log)() diff --git a/src/calibre/ebooks/docx/index.py b/src/calibre/ebooks/docx/index.py index 0ec2902da2..3e7e9dc42f 100644 --- a/src/calibre/ebooks/docx/index.py +++ b/src/calibre/ebooks/docx/index.py @@ -387,6 +387,7 @@ class Index(object): We generated the index object in the constructor. This method writes it into the html. """ + # TODO: Only do this at locations of the INDEX field in the document body = self.convert.body body.append(add_name('Index', self.title_style)) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index 3b0be2febf..5a17d25eab 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -45,13 +45,12 @@ class Text: class Convert(object): - def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, do_index=False, notes_text=None): + def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None): self.docx = DOCX(path_or_stream, log=log) self.ms_pat = re.compile(r'\s{2,}') self.ws_pat = re.compile(r'[\n\r\t]') self.log = self.docx.log self.detect_cover = detect_cover - self.do_index = do_index self.notes_text = notes_text or _('Notes') self.dest_dir = dest_dir or os.getcwdu() self.mi = self.docx.metadata @@ -103,9 +102,7 @@ class Convert(object): # If we are doing an index, do the body part of the processing here. # We need to insert bookmarks at the indexed locations before the # main conversion work. - if self.do_index: - self.log.debug('Generating index') - index = Index(self) + index = Index(self) self.read_page_properties(doc) self.current_rels = relationships_by_id @@ -168,14 +165,13 @@ class Convert(object): parent.text = tabs[-1].tail or '' map(parent.remove, tabs) - # For an index, we now want to append the index object - if self.do_index: - index.generate() - self.images.rid_map = orig_rid_map self.resolve_links() + # For an index, we now want to append the index object + index.generate() + self.styles.cascade(self.layers) self.tables.apply_markup(self.object_map, self.page_map) diff --git a/src/calibre/gui2/convert/docx_input.py b/src/calibre/gui2/convert/docx_input.py index 0fbfb66634..46234c6a36 100644 --- a/src/calibre/gui2/convert/docx_input.py +++ b/src/calibre/gui2/convert/docx_input.py @@ -18,6 +18,6 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, - ['docx_no_cover', 'docx_index', ]) + ['docx_no_cover', ]) self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/docx_input.ui b/src/calibre/gui2/convert/docx_input.ui index 8f3843dd2a..41948118dc 100644 --- a/src/calibre/gui2/convert/docx_input.ui +++ b/src/calibre/gui2/convert/docx_input.ui @@ -21,13 +21,6 @@ - - - - Generate an alphabetical index from embedded index markers - - -