mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
AZW3 Output: Close self closing script/style/title/head tags explicitly as they cause problems in webkit based renderers like the Kindle Fire and calibre's viewers.
This commit is contained in:
parent
512397e4ff
commit
0fa0fca0b5
@ -53,6 +53,7 @@ class KF8Writer(object):
|
|||||||
|
|
||||||
self.log('\tGenerating KF8 markup...')
|
self.log('\tGenerating KF8 markup...')
|
||||||
self.dup_data()
|
self.dup_data()
|
||||||
|
self.cleanup_markup()
|
||||||
self.replace_resource_links()
|
self.replace_resource_links()
|
||||||
self.extract_css_into_flows()
|
self.extract_css_into_flows()
|
||||||
self.extract_svg_into_flows()
|
self.extract_svg_into_flows()
|
||||||
@ -89,6 +90,15 @@ class KF8Writer(object):
|
|||||||
def data(self, item):
|
def data(self, item):
|
||||||
return self._data_cache.get(item.href, item.data)
|
return self._data_cache.get(item.href, item.data)
|
||||||
|
|
||||||
|
def cleanup_markup(self):
|
||||||
|
for item in self.oeb.spine:
|
||||||
|
root = self.data(item)
|
||||||
|
|
||||||
|
# Remove empty script tags as they are pointless
|
||||||
|
for tag in XPath('//h:script')(root):
|
||||||
|
if not tag.text and not tag.get('src', False):
|
||||||
|
tag.getparent().remove(tag)
|
||||||
|
|
||||||
def replace_resource_links(self):
|
def replace_resource_links(self):
|
||||||
''' Replace links to resources (raster images/fonts) with pointers to
|
''' Replace links to resources (raster images/fonts) with pointers to
|
||||||
the MOBI record containing the resource. The pointers are of the form:
|
the MOBI record containing the resource. The pointers are of the form:
|
||||||
|
@ -33,7 +33,8 @@ aid_able_tags = {'a', 'abbr', 'address', 'article', 'aside', 'audio', 'b',
|
|||||||
'video'}
|
'video'}
|
||||||
|
|
||||||
_self_closing_pat = re.compile(bytes(
|
_self_closing_pat = re.compile(bytes(
|
||||||
r'<(?P<tag>%s)(?=[\s/])(?P<arg>[^>]*)/>'%('|'.join(aid_able_tags))),
|
r'<(?P<tag>%s)(?=[\s/])(?P<arg>[^>]*)/>'%('|'.join(aid_able_tags|{'script',
|
||||||
|
'style', 'title', 'head'}))),
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
|
|
||||||
def close_self_closing_tags(raw):
|
def close_self_closing_tags(raw):
|
||||||
@ -118,6 +119,7 @@ class Skeleton(object):
|
|||||||
def render(self, root):
|
def render(self, root):
|
||||||
raw = tostring(root, xml_declaration=True)
|
raw = tostring(root, xml_declaration=True)
|
||||||
raw = raw.replace(b'<html', bytes('<html xmlns="%s"'%XHTML_NS), 1)
|
raw = raw.replace(b'<html', bytes('<html xmlns="%s"'%XHTML_NS), 1)
|
||||||
|
raw = close_self_closing_tags(raw)
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
def calculate_metrics(self, root):
|
def calculate_metrics(self, root):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user