Embed fonts: Create <head> when missing. Fixes #1960180 [Error embedding fonts](https://bugs.launchpad.net/calibre/+bug/1960180)

This commit is contained in:
Kovid Goyal 2022-02-07 08:19:46 +05:30
parent 2adc821a67
commit e52c124224
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -247,7 +247,13 @@ def embed_all_fonts(container, stats, report):
# Add link to CSS in all files that need it # Add link to CSS in all files that need it
for spine_name in modified: for spine_name in modified:
root = container.parsed(spine_name) root = container.parsed(spine_name)
head = root.xpath('//*[local-name()="head"][1]')[0] try:
head = root.xpath('//*[local-name()="head"][1]')[0]
except IndexError:
head = root.makeelement(XHTML('head'))
root.insert(0, head)
head.tail = '\n'
head.text = '\n '
href = container.name_to_href(name, spine_name) href = container.name_to_href(name, spine_name)
etree.SubElement(head, XHTML('link'), rel='stylesheet', type='text/css', href=href).tail = '\n' etree.SubElement(head, XHTML('link'), rel='stylesheet', type='text/css', href=href).tail = '\n'
container.dirty(spine_name) container.dirty(spine_name)