mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Refactor out loc to node into a separate function
This commit is contained in:
parent
46988f0f9a
commit
b73de11b3b
@ -295,8 +295,7 @@ def from_files(container):
|
||||
toc.add(text, name)
|
||||
return toc
|
||||
|
||||
def add_id(container, name, loc):
|
||||
root = container.parsed(name)
|
||||
def node_from_loc(root, loc):
|
||||
body = root.xpath('//*[local-name()="body"]')[0]
|
||||
locs = deque(loc)
|
||||
node = body
|
||||
@ -304,11 +303,15 @@ def add_id(container, name, loc):
|
||||
children = tuple(node.iterchildren(etree.Element))
|
||||
node = children[locs[0]]
|
||||
locs.popleft()
|
||||
return node
|
||||
|
||||
def add_id(container, name, loc):
|
||||
root = container.parsed(name)
|
||||
node = node_from_loc(root, loc)
|
||||
node.set('id', node.get('id', uuid_id()))
|
||||
container.commit_item(name, keep_parsed=True)
|
||||
return node.get('id')
|
||||
|
||||
|
||||
def create_ncx(toc, to_href, btitle, lang, uid):
|
||||
lang = lang.replace('_', '-')
|
||||
ncx = etree.Element(NCX('ncx'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user