mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When upgrading EPUB 2 to EPUB 3 add the epub namespace to all HTML files, for convenience. Fixes #1765944 [Editor:EPUB2 to EPUB3 tool enhancement](https://bugs.launchpad.net/calibre/+bug/1765944)
This commit is contained in:
parent
24ece3b623
commit
7d6a4d54c1
@ -146,6 +146,15 @@ def clean_word_doc(data, log):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_namespace_prefixes(node, nsmap):
|
||||||
|
namespace_uris = frozenset(nsmap.itervalues())
|
||||||
|
fnsmap = {k:v for k, v in node.nsmap.iteritems() if v not in namespace_uris}
|
||||||
|
fnsmap.update(nsmap)
|
||||||
|
if fnsmap != dict(node.nsmap):
|
||||||
|
node = clone_element(node, nsmap=fnsmap, in_context=False)
|
||||||
|
return node
|
||||||
|
|
||||||
|
|
||||||
class HTML5Doc(ValueError):
|
class HTML5Doc(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -307,11 +316,8 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
|
|||||||
nroot.append(elem)
|
nroot.append(elem)
|
||||||
data = nroot
|
data = nroot
|
||||||
|
|
||||||
fnsmap = {k:v for k, v in data.nsmap.iteritems() if v != XHTML_NS}
|
# Remove non default prefixes referring to the XHTML namespace
|
||||||
fnsmap[None] = XHTML_NS
|
data = ensure_namespace_prefixes(data, {None: XHTML_NS})
|
||||||
if fnsmap != dict(data.nsmap):
|
|
||||||
# Remove non default prefixes referring to the XHTML namespace
|
|
||||||
data = clone_element(data, nsmap=fnsmap, in_context=False)
|
|
||||||
|
|
||||||
data = merge_multiple_html_heads_and_bodies(data, log)
|
data = merge_multiple_html_heads_and_bodies(data, log)
|
||||||
# Ensure has a <head/>
|
# Ensure has a <head/>
|
||||||
|
@ -7,7 +7,8 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from calibre.ebooks.metadata.opf_2_to_3 import upgrade_metadata
|
from calibre.ebooks.metadata.opf_2_to_3 import upgrade_metadata
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, xpath
|
from calibre.ebooks.oeb.base import EPUB_NS, OEB_DOCS, xpath
|
||||||
|
from calibre.ebooks.oeb.parse_utils import ensure_namespace_prefixes
|
||||||
from calibre.ebooks.oeb.polish.container import OEB_FONTS
|
from calibre.ebooks.oeb.polish.container import OEB_FONTS
|
||||||
from calibre.ebooks.oeb.polish.opf import get_book_language
|
from calibre.ebooks.oeb.polish.opf import get_book_language
|
||||||
from calibre.ebooks.oeb.polish.toc import (
|
from calibre.ebooks.oeb.polish.toc import (
|
||||||
@ -36,8 +37,9 @@ def collect_properties(container):
|
|||||||
continue
|
continue
|
||||||
name = container.href_to_name(item.get('href'), container.opf_name)
|
name = container.href_to_name(item.get('href'), container.opf_name)
|
||||||
root = container.parsed(name)
|
root = container.parsed(name)
|
||||||
|
root = ensure_namespace_prefixes(root, {'epub': EPUB_NS})
|
||||||
properties = set()
|
properties = set()
|
||||||
container.dirty(name) # Ensure entities are converted
|
container.replace(name, root) # Ensure entities are converted
|
||||||
if xpath(root, '//svg:svg'):
|
if xpath(root, '//svg:svg'):
|
||||||
properties.add('svg')
|
properties.add('svg')
|
||||||
if xpath(root, '//h:script'):
|
if xpath(root, '//h:script'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user