Added Real TOC extraction

This commit is contained in:
Georgy Litvinov 2016-10-03 12:43:29 +03:00 committed by Georgy Litvinov
parent acd74dee18
commit 4c6cc14c95
2 changed files with 35 additions and 2 deletions

View file

@ -29,6 +29,9 @@ import java.util.Hashtable;
import java.util.Stack;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import writer2latex.util.Misc;
@ -144,6 +147,11 @@ public class TextConverter extends ConverterHelper {
// Add cover image
hnode = getDrawCv().insertCoverImage(hnode);
//Extract table:index-body content from TOC
if (!config.includeToc()){
extractRealTOC(onode);
}
//Split pages
onode = (Element) PageSplitter.splitSoftPageBreak(onode,ofr);
// Convert content
@ -167,7 +175,32 @@ public class TextConverter extends ConverterHelper {
bInToc = false;
}
protected int getTocIndex() { return tocCv.getFileIndex(); }
private void extractRealTOC(Element onode) {
NodeList tocs = onode.getElementsByTagName(XMLString.TEXT_TABLE_OF_CONTENT);
int i = 0;
if (tocs == null){
return;
}
System.out.println("extractRealTOC");
while (i < tocs.getLength()){
Node toc = tocs.item(i);
NodeList indexTitle = onode.getElementsByTagName(XMLString.TEXT_INDEX_TITLE);
if (indexTitle == null || indexTitle.item(0) == null){
i++;
continue;
}
while (indexTitle.item(0).hasChildNodes()){
Node child = indexTitle.item(0).getFirstChild();
//Move childnodes before text:table-of-content
System.out.println("insertBefore");
toc.getParentNode().insertBefore(child, toc);
}
i++;
}
return;
}
protected int getTocIndex() { return tocCv.getFileIndex(); }
protected int getAlphabeticalIndex() { return indexCv.getFileIndex(); }

View file

@ -248,7 +248,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
}
}
};
options[INCLUDE_TOC] = new BooleanOption("include_toc","true");
options[INCLUDE_TOC] = new BooleanOption("include_toc","false");
options[INCLUDE_NCX] = new BooleanOption("include_ncx","true");
options[SPLIT_LEVEL] = new IntegerOption("split_level","0") {
@Override public void setString(String sValue) {