Serialization: Dont mangle the name of epub namespaced tags

Also dont normalize boolean attributes
This commit is contained in:
Kovid Goyal 2019-10-27 13:07:19 +05:30
parent 78a97a0e37
commit 3abe43d90c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 15 deletions

View File

@ -25,7 +25,7 @@ from calibre.customize.ui import plugin_for_input_format
from calibre.ebooks import parse_css_length from calibre.ebooks import parse_css_length
from calibre.ebooks.css_transform_rules import StyleDeclaration from calibre.ebooks.css_transform_rules import StyleDeclaration
from calibre.ebooks.oeb.base import ( from calibre.ebooks.oeb.base import (
EPUB_NS, OEB_DOCS, OEB_STYLES, OPF, XHTML, XHTML_NS, XLINK, XPath as _XPath, OEB_DOCS, OEB_STYLES, OPF, XHTML, XHTML_NS, XLINK, XPath as _XPath,
rewrite_links, urlunquote rewrite_links, urlunquote
) )
from calibre.ebooks.oeb.iterator.book import extract_book from calibre.ebooks.oeb.iterator.book import extract_book
@ -704,9 +704,6 @@ def split_name(name):
return None, l return None, l
boolean_attributes = frozenset('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible'.split(',')) # noqa
known_tags = ('img', 'script', 'link', 'image', 'style') known_tags = ('img', 'script', 'link', 'image', 'style')
discarded_tags = ('meta', 'base') discarded_tags = ('meta', 'base')
@ -714,8 +711,6 @@ discarded_tags = ('meta', 'base')
def serialize_elem(elem, nsmap): def serialize_elem(elem, nsmap):
ns, name = split_name(elem.tag) ns, name = split_name(elem.tag)
nl = name.lower() nl = name.lower()
if ns == EPUB_NS:
ns, name = None, 'epub-' + name
if nl in discarded_tags: if nl in discarded_tags:
# Filter out <meta> tags as they have unknown side-effects # Filter out <meta> tags as they have unknown side-effects
# Filter out <base> tags as the viewer uses <base> for URL resolution # Filter out <base> tags as the viewer uses <base> for URL resolution
@ -734,16 +729,11 @@ def serialize_elem(elem, nsmap):
attribs = [] attribs = []
for attr, val in elem.items(): for attr, val in elem.items():
attr_ns, aname = split_name(attr) attr_ns, aname = split_name(attr)
al = aname.lower() attrib = aname, val
if not attr_ns and al in boolean_attributes:
if val and val.lower() in (al, ''):
attribs.append([al, al])
continue
attrib = [aname, val]
if attr_ns: if attr_ns:
attr_ns = nsmap[attr_ns] attr_ns = nsmap[attr_ns]
if attr_ns: if attr_ns:
attrib.append(attr_ns) attrib = aname, val, attr_ns
attribs.append(attrib) attribs.append(attrib)
if attribs: if attribs:
ans['a'] = attribs ans['a'] = attribs

View File

@ -185,9 +185,10 @@ def apply_attributes(src, elem, ns_map):
ns = ns_map[a[2]] ns = ns_map[a[2]]
elem.setAttributeNS(ns, get_prefix(ns) + a[0], a[1]) elem.setAttributeNS(ns, get_prefix(ns) + a[0], a[1])
else: else:
if hide_tooltips and (a[0] is 'title' or a[0] is 'alt'): name = a[0]
if hide_tooltips and (name is 'title' or name is 'alt'):
continue continue
elem.setAttribute(a[0], a[1]) elem.setAttribute(name, a[1])
def process_stack(stack, tag_map, ns_map, load_required, onload): def process_stack(stack, tag_map, ns_map, load_required, onload):
while stack.length: while stack.length: