Refactor out loc to node into a separate function

This commit is contained in:
Kovid Goyal 2013-11-21 09:06:36 +05:30
parent 46988f0f9a
commit b73de11b3b

View File

@ -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'),