Get rid of the option to control index generation

Index will be generated automatically, wherever the INDEX field exists
in the input docx file.
This commit is contained in:
Kovid Goyal 2014-03-30 21:32:09 +05:30
parent 5d4c4b857e
commit a37fe4b717
5 changed files with 8 additions and 22 deletions

View File

@ -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, ' 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 ' 'it will be removed from the document and used as the cover for created ebook. This option '
'turns off that behavior.')), '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)]) recommendations = set([('page_breaks_before', '/', OptionRecommendation.MED)])
def convert(self, stream, options, file_ext, log, accelerators): def convert(self, stream, options, file_ext, log, accelerators):
from calibre.ebooks.docx.to_html import Convert 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)()

View File

@ -387,6 +387,7 @@ class Index(object):
We generated the index object in the constructor. We generated the index object in the constructor.
This method writes it into the html. 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 = self.convert.body
body.append(add_name('Index', self.title_style)) body.append(add_name('Index', self.title_style))

View File

@ -45,13 +45,12 @@ class Text:
class Convert(object): 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.docx = DOCX(path_or_stream, log=log)
self.ms_pat = re.compile(r'\s{2,}') self.ms_pat = re.compile(r'\s{2,}')
self.ws_pat = re.compile(r'[\n\r\t]') self.ws_pat = re.compile(r'[\n\r\t]')
self.log = self.docx.log self.log = self.docx.log
self.detect_cover = detect_cover self.detect_cover = detect_cover
self.do_index = do_index
self.notes_text = notes_text or _('Notes') self.notes_text = notes_text or _('Notes')
self.dest_dir = dest_dir or os.getcwdu() self.dest_dir = dest_dir or os.getcwdu()
self.mi = self.docx.metadata 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. # 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 # We need to insert bookmarks at the indexed locations before the
# main conversion work. # main conversion work.
if self.do_index: index = Index(self)
self.log.debug('Generating index')
index = Index(self)
self.read_page_properties(doc) self.read_page_properties(doc)
self.current_rels = relationships_by_id self.current_rels = relationships_by_id
@ -168,14 +165,13 @@ class Convert(object):
parent.text = tabs[-1].tail or '' parent.text = tabs[-1].tail or ''
map(parent.remove, tabs) 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.images.rid_map = orig_rid_map
self.resolve_links() self.resolve_links()
# For an index, we now want to append the index object
index.generate()
self.styles.cascade(self.layers) self.styles.cascade(self.layers)
self.tables.apply_markup(self.object_map, self.page_map) self.tables.apply_markup(self.object_map, self.page_map)

View File

@ -18,6 +18,6 @@ class PluginWidget(Widget, Ui_Form):
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, Widget.__init__(self, parent,
['docx_no_cover', 'docx_index', ]) ['docx_no_cover', ])
self.initialize_options(get_option, get_help, db, book_id) self.initialize_options(get_option, get_help, db, book_id)

View File

@ -21,13 +21,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="opt_docx_index">
<property name="text">
<string>Generate an alphabetical index from embedded index markers</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">