mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #842882 (calibre.epub has 2 copies of content)
This commit is contained in:
parent
48363e9d69
commit
6695f0d346
@ -180,30 +180,30 @@ class InterfaceAction(QObject):
|
|||||||
description=None, triggered=None, shortcut_name=None):
|
description=None, triggered=None, shortcut_name=None):
|
||||||
'''
|
'''
|
||||||
Convenience method to easily add actions to a QMenu.
|
Convenience method to easily add actions to a QMenu.
|
||||||
|
Returns the created QAction, This action has one extra attribute
|
||||||
|
calibre_shortcut_unique_name which if not None refers to the unique
|
||||||
|
name under which this action is registered with the keyboard manager.
|
||||||
|
|
||||||
:param menu: The QMenu the newly created action will be added to
|
:param menu: The QMenu the newly created action will be added to
|
||||||
:param unique_name: A unique name for this action, this must be
|
:param unique_name: A unique name for this action, this must be
|
||||||
globally unique, so make it as descriptive as possible. If in doubt add
|
globally unique, so make it as descriptive as possible. If in doubt add
|
||||||
a uuid to it.
|
a uuid to it.
|
||||||
:param text: The text of the action.
|
:param text: The text of the action.
|
||||||
:param icon: Either a QIcon or a file name. The file name is passed to
|
:param icon: Either a QIcon or a file name. The file name is passed to
|
||||||
the I() builtin, so you do not need to pass the full path to the images
|
the I() builtin, so you do not need to pass the full path to the images
|
||||||
directory.
|
directory.
|
||||||
:param shortcut: A string, a list of strings, None or False. If False,
|
:param shortcut: A string, a list of strings, None or False. If False,
|
||||||
no keyboard shortcut is registered for this action. If None, a keyboard
|
no keyboard shortcut is registered for this action. If None, a keyboard
|
||||||
shortcut with no default keybinding is registered. String and list of
|
shortcut with no default keybinding is registered. String and list of
|
||||||
strings register a shortcut with default keybinding as specified.
|
strings register a shortcut with default keybinding as specified.
|
||||||
:param description: A description for this action. Used to set
|
:param description: A description for this action. Used to set
|
||||||
tooltips.
|
tooltips.
|
||||||
:param triggered: A callable which is connected to the triggered signal
|
:param triggered: A callable which is connected to the triggered signal
|
||||||
of the created action.
|
of the created action.
|
||||||
:param shortcut_name: The test displayed to the user when customizing
|
:param shortcut_name: The test displayed to the user when customizing
|
||||||
the keyboard shortcuts for this action. By default it is set to the
|
the keyboard shortcuts for this action. By default it is set to the
|
||||||
value of ``text``.
|
value of ``text``.
|
||||||
|
|
||||||
:return: The created QAction, This action has one extra attribute
|
|
||||||
calibre_shortcut_unique_name which if not None refers to the unique
|
|
||||||
name under which this action is registered with the keyboard manager.
|
|
||||||
'''
|
'''
|
||||||
if shortcut_name is None:
|
if shortcut_name is None:
|
||||||
shortcut_name = unicode(text)
|
shortcut_name = unicode(text)
|
||||||
|
@ -6,7 +6,9 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, time
|
import os, time, glob
|
||||||
|
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
from sphinx.builders.epub import EpubBuilder
|
from sphinx.builders.epub import EpubBuilder
|
||||||
|
|
||||||
@ -55,4 +57,38 @@ class EPUBHelpBuilder(EpubBuilder):
|
|||||||
def build_epub(self, outdir, *args, **kwargs):
|
def build_epub(self, outdir, *args, **kwargs):
|
||||||
if self.config.epub_cover:
|
if self.config.epub_cover:
|
||||||
self.add_cover(outdir, self.config.epub_cover)
|
self.add_cover(outdir, self.config.epub_cover)
|
||||||
|
self.fix_duplication_bugs(outdir)
|
||||||
EpubBuilder.build_epub(self, outdir, *args, **kwargs)
|
EpubBuilder.build_epub(self, outdir, *args, **kwargs)
|
||||||
|
|
||||||
|
def fix_duplication_bugs(self, outdir):
|
||||||
|
opf = glob.glob(outdir+os.sep+'*.opf')[0]
|
||||||
|
root = etree.fromstring(open(opf, 'rb').read())
|
||||||
|
seen = set()
|
||||||
|
for x in root.xpath(
|
||||||
|
'//*[local-name()="spine"]/*[local-name()="itemref"]'):
|
||||||
|
idref = x.get('idref')
|
||||||
|
if idref in seen:
|
||||||
|
x.getparent().remove(x)
|
||||||
|
else:
|
||||||
|
seen.add(idref)
|
||||||
|
|
||||||
|
with open(opf, 'wb') as f:
|
||||||
|
f.write(etree.tostring(root, encoding='utf-8', xml_declaration=True))
|
||||||
|
|
||||||
|
|
||||||
|
ncx = glob.glob(outdir+os.sep+'*.ncx')[0]
|
||||||
|
root = etree.fromstring(open(ncx, 'rb').read())
|
||||||
|
seen = set()
|
||||||
|
for x in root.xpath(
|
||||||
|
'//*[local-name()="navMap"]/*[local-name()="navPoint"]'):
|
||||||
|
text = x.xpath('descendant::*[local-name()="text"]')[0]
|
||||||
|
text = text.text
|
||||||
|
if text in seen:
|
||||||
|
x.getparent().remove(x)
|
||||||
|
else:
|
||||||
|
seen.add(text)
|
||||||
|
|
||||||
|
with open(ncx, 'wb') as f:
|
||||||
|
f.write(etree.tostring(root, encoding='utf-8', xml_declaration=True))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user