From 1e2429b3be2fc0dd06f333a7b1406b34cf159301 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 24 Sep 2012 21:33:47 +0100 Subject: [PATCH] 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. --- unireader.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index 5e4263714..1f1aa7363 100644 --- a/unireader.lua +++ b/unireader.lua @@ -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