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)
|
toc.add(text, name)
|
||||||
return toc
|
return toc
|
||||||
|
|
||||||
def add_id(container, name, loc):
|
def node_from_loc(root, loc):
|
||||||
root = container.parsed(name)
|
|
||||||
body = root.xpath('//*[local-name()="body"]')[0]
|
body = root.xpath('//*[local-name()="body"]')[0]
|
||||||
locs = deque(loc)
|
locs = deque(loc)
|
||||||
node = body
|
node = body
|
||||||
@ -304,11 +303,15 @@ def add_id(container, name, loc):
|
|||||||
children = tuple(node.iterchildren(etree.Element))
|
children = tuple(node.iterchildren(etree.Element))
|
||||||
node = children[locs[0]]
|
node = children[locs[0]]
|
||||||
locs.popleft()
|
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()))
|
node.set('id', node.get('id', uuid_id()))
|
||||||
container.commit_item(name, keep_parsed=True)
|
container.commit_item(name, keep_parsed=True)
|
||||||
return node.get('id')
|
return node.get('id')
|
||||||
|
|
||||||
|
|
||||||
def create_ncx(toc, to_href, btitle, lang, uid):
|
def create_ncx(toc, to_href, btitle, lang, uid):
|
||||||
lang = lang.replace('_', '-')
|
lang = lang.replace('_', '-')
|
||||||
ncx = etree.Element(NCX('ncx'),
|
ncx = etree.Element(NCX('ncx'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user