diff --git a/source/java/writer2latex/xhtml/GreenstoneTags.java b/source/java/writer2latex/xhtml/GreenstoneTags.java
index 6db976f..e76cee5 100644
--- a/source/java/writer2latex/xhtml/GreenstoneTags.java
+++ b/source/java/writer2latex/xhtml/GreenstoneTags.java
@@ -35,32 +35,26 @@ public class GreenstoneTags {
pageSection = false;
}
- //If stack not empty
- //Close all sections with level less than current
- if (!headerStack.isEmpty()) {
- while (nLevel <= headerStack.peek()){
- closeSection(hnode);
- headerStack.poll();
- if (headerStack.isEmpty()){ break;}
-
- }
- }
- //System.out.println(sLevel +">" +headerStack.peek() );
+ closeHeadingSections(hnode, nLevel);
Node nextNode = currentNode.getNextSibling();
//Useless to open section if we are at end of the document
if (nextNode != null){
- //Open Heading section
String title = getTitle(currentNode);
-
+ //Open Heading section
openSection(hnode, title);
headerStack.offerFirst(Integer.parseInt(sLevel));
- //System.out.println("Current " + sLevel + " stack " + headerStack.peek() + "SUM" + headerStack.size());
-
- if (!(nextNode.getNodeType() == Node.ELEMENT_NODE
- && nextNode.getNodeName().equals(XMLString.TEXT_H)
- && Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL) != null
- && !Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty())) {
- openSection(hnode, pageNum);
+ //If next node is not a heading element with outline number and tags type is headings-pages
+ //Then open paged section
+ if (!(
+ nextNode.getNodeType() == Node.ELEMENT_NODE
+ && nextNode.getNodeName().equals(XMLString.TEXT_H)
+ && Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL) != null
+ && !Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty()
+ )
+ && tagsType.equals("headings-pages")
+ ) {
+ //Open page section
+ openSection(hnode, pageNum);
}
}
@@ -93,12 +87,17 @@ public class GreenstoneTags {
}
}
//Method to open main document tag
- protected static void StartDocument(Node hnode, String title, String type){
+ protected static void StartDocument(Node hnode, String title, String type, int pageNum){
tagsType = type;
if (tagsType.equals("none")){
return;
}
+ //Create main document section
openSection(hnode, title);
+ if (tagsType.equals("pages")){
+ //Open page section
+ openSection(hnode, pageNum);
+ }
}
@@ -112,6 +111,8 @@ public class GreenstoneTags {
pageSection = false;
}
closeSection(hnode);
+ //Clean stack, close all sections
+ closeHeadingSections(hnode, 0);
}
private static String getTitle(Node currentNode) {
@@ -145,7 +146,6 @@ public class GreenstoneTags {
String commentText = "\n\n" + pageNum
+ "\n" + pageNum + "\n";
Node openSection = doc.createComment(commentText);
- //Node openSection = doc.createTextNode(commentText);
// insert open section comment before header node
hnode.appendChild(openSection);
pageSection = true;
@@ -166,4 +166,21 @@ public class GreenstoneTags {
//insert open section comment before header node
hnode.appendChild(closeSection);
}
+
+ private static void closeHeadingSections(Node hnode, int nLevel){
+ if (headerStack.isEmpty()) {
+ return;
+ }
+ //Close all sections with level less than current
+ while (nLevel <= headerStack.peek()) {
+ closeSection(hnode);
+ headerStack.poll();
+ if (headerStack.isEmpty()) {
+ break;
+ }
+
+ }
+
+ }
}
+
\ No newline at end of file
diff --git a/source/java/writer2latex/xhtml/TextConverter.java b/source/java/writer2latex/xhtml/TextConverter.java
index 75d2d33..219ec41 100644
--- a/source/java/writer2latex/xhtml/TextConverter.java
+++ b/source/java/writer2latex/xhtml/TextConverter.java
@@ -1582,7 +1582,7 @@ public class TextConverter extends ConverterHelper {
//Start tagging
String sTitle = converter.getTitle();
- GreenstoneTags.StartDocument(hnode, sTitle,greenstoneTagsType);
+ GreenstoneTags.StartDocument(hnode, sTitle,greenstoneTagsType, pageNum);
//Print header
addHeader(hnode);