extract real TOC

This commit is contained in:
Georgy Litvinov 2016-10-03 14:29:52 +03:00 committed by Georgy Litvinov
parent 4c6cc14c95
commit 3b64ebe942

View file

@ -151,8 +151,7 @@ public class TextConverter extends ConverterHelper {
if (!config.includeToc()){
extractRealTOC(onode);
}
//Split pages
//Split pages
onode = (Element) PageSplitter.splitSoftPageBreak(onode,ofr);
// Convert content
hnode = (Element)traverseBlockText(onode,hnode);
@ -181,18 +180,30 @@ public class TextConverter extends ConverterHelper {
if (tocs == null){
return;
}
System.out.println("extractRealTOC");
System.out.println("extractRealTOC " + tocs.getLength());
while (i < tocs.getLength()){
Node toc = tocs.item(i);
NodeList indexTitle = onode.getElementsByTagName(XMLString.TEXT_INDEX_TITLE);
if (indexTitle == null || indexTitle.item(0) == null){
NodeList indexBody = ((Element)toc).getElementsByTagName(XMLString.TEXT_INDEX_BODY);
if (indexBody == null || indexBody.item(0) == null){
i++;
continue;
}
while (indexTitle.item(0).hasChildNodes()){
Node child = indexTitle.item(0).getFirstChild();
while (indexBody.item(0).hasChildNodes()){
Node child = indexBody.item(0).getFirstChild();
if (child.getNodeType() == Node.ELEMENT_NODE
&&
((Element) child).getTagName().equals(XMLString.TEXT_INDEX_TITLE)
){
while(child.hasChildNodes()){
toc.getParentNode().insertBefore(child.getFirstChild(),toc);
}
//kamikadze
child.getParentNode().removeChild(child);
continue;
}
//Move childnodes before text:table-of-content
System.out.println("insertBefore");
toc.getParentNode().insertBefore(child, toc);
}
i++;