EPUB 3: When setting authors and there are only editors, remove the editors. Matches EPUB 2 behavior and is symmetric with using only editors as authors when reading the metadata

This commit is contained in:
Kovid Goyal 2021-11-14 18:08:59 +05:30
parent 5ca15b9175
commit 1e05b40f7a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -483,11 +483,17 @@ def read_authors(root, prefixes, refines):
def set_authors(root, prefixes, refines, authors):
ensure_prefix(root, prefixes, 'marc')
removals = []
for role in ('aut', 'edt'):
for item in XPath('./opf:metadata/dc:creator')(root):
props = properties_for_id_with_scheme(item.get('id'), prefixes, refines)
opf_role = item.get(OPF('role'))
if (opf_role and opf_role.lower() != 'aut') or (props.get('role') and not is_relators_role(props, 'aut')):
if (opf_role and opf_role.lower() != role) or (props.get('role') and not is_relators_role(props, role)):
continue
removals.append(item)
if removals:
break
for item in removals:
remove_element(item, refines)
metadata = XPath('./opf:metadata')(root)[0]
for author in authors: