Fix for the issue #311.

Children nodes that have no [apparent] parent should be adopted
by the "_HEAD" i.e. the root of the whole tree.
This commit is contained in:
Tigran Aivazian
2012-09-24 21:33:47 +01:00
parent 47b056861b
commit 1e2429b3be

View File

@@ -1642,14 +1642,22 @@ function UniReader:fillToc()
end
elseif (v.depth == prev_depth) then --> k and prev are siblings
parent[k] = parent[prev]
table.insert(self.toc_children[parent[k]], k)
if not self.toc_children[parent[k]] then
table.insert(self.toc_children[0],k)
else
table.insert(self.toc_children[parent[k]], k)
end
else --> k and prev must have a common (possibly virtual) ancestor
local par = parent[prev]
while (self.toc[par].depth > v.depth) do
par = parent[par]
end
parent[k] = parent[par]
table.insert(self.toc_children[parent[k]], k)
if not self.toc_children[parent[k]] then
table.insert(self.toc_children[0],k)
else
table.insert(self.toc_children[parent[k]], k)
end
end
prev = k
prev_depth = self.toc[prev].depth