mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Apply content based manifest properties
This commit is contained in:
parent
0234d75aa2
commit
b604aa7acc
@ -41,12 +41,15 @@ CALIBRE_NS = 'http://calibre.kovidgoyal.net/2009/metadata'
|
||||
RE_NS = 'http://exslt.org/regular-expressions'
|
||||
MBP_NS = 'http://www.mobipocket.com'
|
||||
EPUB_NS = 'http://www.idpf.org/2007/ops'
|
||||
MATHML_NS = 'http://www.w3.org/1998/Math/MathML'
|
||||
|
||||
XPNSMAP = {'h': XHTML_NS, 'o1': OPF1_NS, 'o2': OPF2_NS,
|
||||
'd09': DC09_NS, 'd10': DC10_NS, 'd11': DC11_NS,
|
||||
'xsi': XSI_NS, 'dt': DCTERMS_NS, 'ncx': NCX_NS,
|
||||
'svg': SVG_NS, 'xl': XLINK_NS, 're': RE_NS,
|
||||
'mbp': MBP_NS, 'calibre': CALIBRE_NS, 'epub':EPUB_NS}
|
||||
XPNSMAP = {
|
||||
'h': XHTML_NS, 'o1': OPF1_NS, 'o2': OPF2_NS, 'd09': DC09_NS,
|
||||
'd10': DC10_NS, 'd11': DC11_NS, 'xsi': XSI_NS, 'dt': DCTERMS_NS,
|
||||
'ncx': NCX_NS, 'svg': SVG_NS, 'xl': XLINK_NS, 're': RE_NS,
|
||||
'mathml': MATHML_NS, 'mbp': MBP_NS, 'calibre': CALIBRE_NS,
|
||||
'epub':EPUB_NS
|
||||
}
|
||||
|
||||
OPF1_NSMAP = {'dc': DC11_NS, 'oebpackage': OPF1_NS}
|
||||
OPF2_NSMAP = {'opf': OPF2_NS, 'dc': DC11_NS, 'dcterms': DCTERMS_NS,
|
||||
|
@ -2,16 +2,44 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from __future__ import (absolute_import, division, print_function,
|
||||
unicode_literals)
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from calibre.ebooks.metadata.opf_2_to_3 import upgrade_metadata
|
||||
from calibre.ebooks.oeb.base import OEB_DOCS, xpath
|
||||
|
||||
|
||||
def add_properties(item, *props):
|
||||
existing = set((item.get('properties') or '').split())
|
||||
existing |= set(props)
|
||||
item.set('properties', ' '.join(sorted(existing)))
|
||||
|
||||
|
||||
def collect_properties(container):
|
||||
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'):
|
||||
mt = item.get('media-type') or ''
|
||||
if mt.lower() not in OEB_DOCS:
|
||||
continue
|
||||
name = container.href_to_name(item.get('href'), container.opf_name)
|
||||
root = container.parsed(name)
|
||||
properties = set()
|
||||
container.dirty(name) # Ensure entities are converted
|
||||
if xpath(root, '//svg:svg'):
|
||||
properties.add('svg')
|
||||
if xpath(root, '//h:script'):
|
||||
properties.add('scripted')
|
||||
if xpath(root, '//mathml:math'):
|
||||
properties.add('mathml')
|
||||
if xpath(root, '//epub:switch'):
|
||||
properties.add('switch')
|
||||
if properties:
|
||||
add_properties(item, *tuple(properties))
|
||||
|
||||
|
||||
def epub_2_to_3(container, report):
|
||||
upgrade_metadata(container.opf)
|
||||
container.dirty(container.opf_name)
|
||||
collect_properties(container)
|
||||
container.opf.set('version', '3.0')
|
||||
container.dirty(container.opf_name)
|
||||
|
||||
|
||||
def upgrade_book(container, report):
|
||||
|
Loading…
x
Reference in New Issue
Block a user