From 457caad4fc4d7f12f5e3298395c5c7e0d05b9eca Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 24 Jul 2020 19:31:05 +0200 Subject: [PATCH] Refactored list item split method --- src/main/java/w2phtml/xhtml/ODFPageSplitter.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java index db9dd90..fb01536 100644 --- a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java +++ b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java @@ -199,12 +199,12 @@ public class ODFPageSplitter { } else if (nodeName.equals(TEXT_LIST_ITEM)) { if (containsSPB(child)){ - Node listItemFirstPart = child.cloneNode(false); + //remove SPB, move previous nodes to firstPart. - if (handleListItem(listItemFirstPart,child)){ + if (handleListItem(child)){ dataMoved = true; //Add first part of list item to previous list item - listFirstPart.appendChild(listItemFirstPart); + listFirstPart.appendChild(child.getPreviousSibling()); //Get list parent node and move cutted node //After First Part and SPB but before this list; //TODO!!!!!!!!!! @@ -242,7 +242,9 @@ public class ODFPageSplitter { } //If SPB before first item - return false, remove SPB //Otherwise add childNodes before SPB to firstPart, return true - private static boolean handleListItem(Node listItemFirstPart, Node listItem){ + private static boolean handleListItem(Node listItem){ + Node listItemFirstPart = listItem.cloneNode(false); + Node parent = listItem.getParentNode(); int i = 0; boolean dataMoved = false; NodeList listItemNodes = listItem.getChildNodes(); @@ -283,6 +285,9 @@ public class ODFPageSplitter { } //check internal nodes } + if(dataMoved) { + parent.insertBefore(listItemFirstPart, listItem); + } return dataMoved; } //Needs finish