mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Make OPF generation compliant with epubcheck
This commit is contained in:
commit
c4f3e1c8d8
@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<package version="2.0"
|
||||
xmlns:opf="http://www.idpf.org/2007/opf"
|
||||
xmlns="http://www.idpf.org/2007/opf"
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
unique-identifier="${__appname__}_id"
|
||||
|
||||
>
|
||||
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<dc:title py:with="attrs={'files-as':mi.title_sort}" py:attrs="attrs">${mi.title}</dc:title>
|
||||
<dc:creator opf:role="aut" py:for="i, author in enumerate(mi.authors)" py:with="attrs={'file-as':mi.author_sort if i==0 else None}" py:attrs="attrs">${author}</dc:creator>
|
||||
<dc:identifier scheme="${__appname__}" id="${__appname__}_id">${mi.application_id}</dc:identifier>
|
||||
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
||||
<dc:title py:with="attrs={'opf:files-as':mi.title_sort}" py:attrs="attrs">${mi.title}</dc:title>
|
||||
<dc:creator opf:role="aut" py:for="i, author in enumerate(mi.authors)" py:with="attrs={'opf:file-as':mi.author_sort if i==0 else None}" py:attrs="attrs">${author}</dc:creator>
|
||||
<dc:identifier opf:scheme="${__appname__}" id="${__appname__}_id">${mi.application_id}</dc:identifier>
|
||||
|
||||
<dc:language>${mi.language if mi.language else 'Unknown'}</dc:language>
|
||||
<dc:type py:if="mi.category">${mi.category}</dc:type>
|
||||
|
@ -573,6 +573,7 @@ class NamespaceFlattener(object):
|
||||
def __call__(self, stream):
|
||||
prefixes = dict([(v, [k]) for k, v in self.prefixes.items()])
|
||||
namespaces = {XML_NAMESPACE.uri: ['xml']}
|
||||
default = prefixes.get('', [''])
|
||||
def _push_ns(prefix, uri):
|
||||
namespaces.setdefault(uri, []).append(prefix)
|
||||
prefixes.setdefault(prefix, []).append(uri)
|
||||
@ -596,14 +597,14 @@ class NamespaceFlattener(object):
|
||||
|
||||
tagname = tag.localname
|
||||
tagns = tag.namespace
|
||||
if tagns:
|
||||
if tagns and tagns != default[-1]:
|
||||
if tagns in namespaces:
|
||||
prefix = namespaces[tagns][-1]
|
||||
if prefix:
|
||||
tagname = u'%s:%s' % (prefix, tagname)
|
||||
else:
|
||||
_push_ns_attr((u'xmlns', tagns))
|
||||
_push_ns('', tagns)
|
||||
default.push(tagns)
|
||||
|
||||
new_attrs = []
|
||||
for attr, value in attrs:
|
||||
@ -626,7 +627,7 @@ class NamespaceFlattener(object):
|
||||
elif kind is END:
|
||||
tagname = data.localname
|
||||
tagns = data.namespace
|
||||
if tagns:
|
||||
if tagns and tagns != default[-1]:
|
||||
prefix = namespaces[tagns][-1]
|
||||
if prefix:
|
||||
tagname = u'%s:%s' % (prefix, tagname)
|
||||
@ -634,12 +635,19 @@ class NamespaceFlattener(object):
|
||||
|
||||
elif kind is START_NS:
|
||||
prefix, uri = data
|
||||
if uri not in namespaces:
|
||||
prefix = prefixes.get(uri, [prefix])[-1]
|
||||
push_attr = False
|
||||
if prefix is '' and default[-1] != uri:
|
||||
default.append(uri)
|
||||
_push_ns_attr(_make_ns_attr(prefix, uri))
|
||||
_push_ns(prefix, uri)
|
||||
elif uri not in namespaces:
|
||||
prefix = namespaces.get(uri, [prefix])[-1]
|
||||
_push_ns_attr(_make_ns_attr(prefix, uri))
|
||||
if prefix is not '':
|
||||
_push_ns(prefix, uri)
|
||||
|
||||
elif kind is END_NS:
|
||||
if data is '':
|
||||
default.pop()
|
||||
if data in prefixes:
|
||||
uris = prefixes.get(data)
|
||||
uri = uris.pop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user