diff --git a/src/main/java/writer2latex/xhtml/PageSplitter.java b/src/main/java/writer2latex/xhtml/PageSplitter.java
index 37fdd6c..c1205de 100644
--- a/src/main/java/writer2latex/xhtml/PageSplitter.java
+++ b/src/main/java/writer2latex/xhtml/PageSplitter.java
@@ -35,8 +35,9 @@ public class PageSplitter {
StyleWithProperties style = null;
if ((nodeName.equals(TEXT_P) || nodeName.equals(TEXT_H))) {
//If SPB not the first node
- if (handleParagraph(childFirstPart, child)){
- onode.insertBefore(childFirstPart, child);
+ Node paraFirstPart = handleParagraph(child);
+ if (paraFirstPart != null){
+ onode.insertBefore(paraFirstPart, child);
style = ofr.getParStyle(Misc.getAttribute(child, TEXT_STYLE_NAME));
}
} else if (nodeName.equals(TABLE_TABLE)) {
@@ -169,9 +170,9 @@ public class PageSplitter {
}
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
-
- if (handleParagraph(listItemChildFirstPart, listItemChild)){
- listItemFirstPart.appendChild(listItemChildFirstPart);
+ Node paraFirstPart = handleParagraph(listItemChild);
+ if (paraFirstPart != null){
+ listItemFirstPart.appendChild(paraFirstPart);
dataMoved=true;
}
}
@@ -427,15 +428,14 @@ public class PageSplitter {
if ((cellChildNode.getNodeType() == Node.ELEMENT_NODE)) {
String nodeName = cellChildNode.getNodeName();
if (containsSPB(cellChildNode)){
- Node cellChildFirstPart = cellChildNode.cloneNode(false);
if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){
// remove inner soft page break node
cellNode.removeChild(cellChildNode);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
-
- if (handleParagraph(cellChildFirstPart, cellChildNode)){
- cellFirstPart.appendChild(cellChildFirstPart);
+ Node paraFirstPart = handleParagraph(cellChildNode);
+ if (paraFirstPart != null){
+ cellFirstPart.appendChild(paraFirstPart);
dataMoved=true;
}
}
@@ -472,9 +472,9 @@ public class PageSplitter {
sectionNode.removeChild(sectionChildNode);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
-
- if (handleParagraph(sectionChildFirstPart, sectionChildNode)){
- sectionFirstPart.appendChild(sectionChildFirstPart);
+ Node paraFirstPart = handleParagraph(sectionChildNode);
+ if (paraFirstPart != null){
+ sectionFirstPart.appendChild(paraFirstPart);
dataMoved=true;
}
} else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
@@ -517,10 +517,11 @@ public class PageSplitter {
}
- private static boolean handleParagraph(Node paraBefore, Node paraAfter) {
+ private static Node handleParagraph(Node para) {
+ Node paraBefore = para.cloneNode(false);
boolean dataMoved = false;
int i = 0;
- NodeList paraChildNodes = paraAfter.getChildNodes();
+ NodeList paraChildNodes = para.getChildNodes();
while (paraChildNodes.getLength() > i) {
Node paraChildNode = paraChildNodes.item(i);
//NOT TEXT NODES
@@ -565,13 +566,13 @@ public class PageSplitter {
}
// In case paragraph is empty add space to prevent it's removing
if (paraNextNode == null && paraPrevNode == null){
- Document doc = paraAfter.getOwnerDocument();
+ Document doc = para.getOwnerDocument();
Node space = doc.createTextNode(" ");
- paraAfter.insertBefore(space, paraChildNode);
+ para.insertBefore(space, paraChildNode);
}
// remove inner soft page break node
- paraAfter.removeChild(paraChildNode);
+ para.removeChild(paraChildNode);
/* Check if next node in para is text and first char is a letter
* Check if last node in paraFirstPart is text and last char is a letter
@@ -599,9 +600,13 @@ public class PageSplitter {
}
}
- removeIndent(paraAfter);
+ if (dataMoved) {
+ removeIndent(para);
+ return paraBefore;
+ }
- return dataMoved;
+
+ return null;
}
private static void removeIndent(Node paraAfter) {
String baseStyleName = Misc.getAttribute(paraAfter, TEXT_STYLE_NAME);