diff --git a/src/main/java/w2phtml/pageSplitters/ListItemSplitter.java b/src/main/java/w2phtml/pageSplitters/ListItemSplitter.java
index 5b1955a..67b9471 100644
--- a/src/main/java/w2phtml/pageSplitters/ListItemSplitter.java
+++ b/src/main/java/w2phtml/pageSplitters/ListItemSplitter.java
@@ -8,6 +8,7 @@ import static w2phtml.office.XMLString.TEXT_SOFT_PAGE_BREAK;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import pro.litvinovg.xml.Debug;
import w2phtml.office.OfficeReader;
public class ListItemSplitter extends BasicSplitter implements ISplitter {
@@ -20,6 +21,8 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
public boolean Split(Node listItem) {
Node listItemFirstPart = listItem.cloneNode(false);
Node parent = listItem.getParentNode();
+ //System.out.println("----Start Item------");
+ //Debug.prettyPrintXml(parent);
int i = 0;
boolean dataMoved = false;
NodeList listItemNodes = listItem.getChildNodes();
@@ -33,10 +36,9 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) {
//Remove SPB.Return result
listItem.removeChild(listItemChild);
+ //System.out.println("LIST ITEM SPLITTER REMOVE SPB");
} else if (nodeName.equals(TEXT_LIST)) {
- if (factory.split(listItemChild)){
- dataMoved=true;
- }
+ factory.split(listItemChild);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
if (factory.split(listItemChild)){
@@ -63,6 +65,8 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
if(dataMoved) {
parent.insertBefore(listItemFirstPart, listItem);
}
+ //System.out.println("-----FINISH Item-----");
+ //Debug.prettyPrintXml(parent);
return dataMoved;
}
diff --git a/src/main/java/w2phtml/pageSplitters/ListSplitter.java b/src/main/java/w2phtml/pageSplitters/ListSplitter.java
index 446f5d2..131d044 100644
--- a/src/main/java/w2phtml/pageSplitters/ListSplitter.java
+++ b/src/main/java/w2phtml/pageSplitters/ListSplitter.java
@@ -3,8 +3,10 @@ package w2phtml.pageSplitters;
import static w2phtml.office.XMLString.TEXT_CONTINUE_NUMBERING;
import static w2phtml.office.XMLString.TEXT_LIST_HEADER;
import static w2phtml.office.XMLString.TEXT_LIST_ITEM;
+import static w2phtml.office.XMLString.TEXT_LIST;
import static w2phtml.office.XMLString.TEXT_SOFT_PAGE_BREAK;
+import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -22,11 +24,13 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
@Override
public boolean Split(Node list) {
Node parent = list.getParentNode();
+ // System.out.println("----Start ListSplitter------");
+ // Debug.prettyPrintXml(parent);
Node listFirstPart = list.cloneNode(false);
NodeList listNodes = list.getChildNodes();
Document document = list.getOwnerDocument();
Element softPageBreak = document.createElement(TEXT_SOFT_PAGE_BREAK);
- Node hangingItem = null;
+ Node nextPageItemPart = null;
int i = 0;
boolean dataMoved = false;
while (listNodes.getLength() > i) {
@@ -52,11 +56,11 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
// Add first part of list item to previous list item
listFirstPart.appendChild(child.getPreviousSibling());
if (child.hasChildNodes()) {
- hangingItem = child;
+ nextPageItemPart = child;
} else {
list.removeChild(child);
}
- }
+ }
// Debug.printNode(child);
break;
@@ -75,20 +79,35 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true");
parent.insertBefore(listFirstPart, list);
parent.insertBefore(softPageBreak, list);
- if (hangingItem != null) {
- i = 0;
- NodeList freeNodes = hangingItem.getChildNodes();
- while (freeNodes.getLength() > 0) {
- Node freeNode = freeNodes.item(i);
- parent.insertBefore(freeNode, list);
- }
- list.removeChild(hangingItem);
- }
+ // System.out.println("LIST FIRST PART");
+ // Debug.printNode(listFirstPart);
+ // TODO: Create dummy list style to override list item to not teleport
+ // second part but making it list item without list mark
+
+ if (nextPageItemPart != null) {
+ Node nextPageFirstNode = nextPageItemPart.getFirstChild();
+ i = 0;
+ NodeList freeNodes = nextPageItemPart.getChildNodes();
+ while (freeNodes.getLength() > 0) {
+ Node freeNode = freeNodes.item(i);
+ String freeNodeName = freeNode.getNodeName();
+ if (StringUtils.equals(TEXT_LIST, freeNodeName)) {
+ break;
+ }
+ parent.insertBefore(freeNode, list);
+ }
+ if (!nextPageItemPart.hasChildNodes()) {
+ list.removeChild(nextPageItemPart);
+ }
+ }
} else {
- //If SPB right before list items
- parent.insertBefore(softPageBreak, list);
+ // If SPB right before list items
+ // parent.insertBefore(softPageBreak, list);
}
+ // System.out.println("----Finish ListSplitter------");
+
+ // Debug.prettyPrintXml(parent);
return dataMoved;
}