Skip to content

Commit

Permalink
Fixed #515 HTML service text between table is not inserted.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Nov 27, 2023
1 parent e3b071e commit 99030b8
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -876,20 +876,23 @@ private void createNeededParagraphes(MParagraph parent) {
MList paragraphList = new MListImpl();
MParagraph currentParagraph = createEmptyParagraphWithSameStyle(parent, paragraphList);
boolean paragraphEncountered = false;
boolean tableEncountered = false;
for (MElement child : parentContents) {

if (child instanceof MParagraph || child instanceof MTable) {
paragraphEncountered = paragraphEncountered || child instanceof MParagraphImpl;
paragraphEncountered = true;
tableEncountered = child instanceof MTable;
if (!paragraphList.isEmpty()) {
newParent.add(currentParagraph);
paragraphList = new MListImpl();
currentParagraph = createEmptyParagraphWithSameStyle(parent, paragraphList);
}
newParent.add(child);
} else if (paragraphEncountered) {
if (!(child == MPagination.ligneBreak && paragraphList.isEmpty())) {
if (tableEncountered || !(child == MPagination.ligneBreak && paragraphList.isEmpty())) {
paragraphList.add(child);
}
tableEncountered = false;
} else {
newParent.add(child);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ private XWPFParagraph insertObject(XWPFParagraph paragraph, Object object, XWPFR
} else if (object instanceof MHyperLink) {
res = insertMHyperLink(paragraph, run, (MHyperLink) object);
} else if (object instanceof MBookmark) {
insertMBookmark(paragraph, run, (MBookmark) object);
res = paragraph;
res = insertMBookmark(paragraph, run, (MBookmark) object);
} else if (object instanceof MImage) {
if (object != MImage.EMPTY) {
final XWPFRun imageRun = insertFieldRunReplacement(paragraph, run, "");
insertMImage((XWPFParagraph) imageRun.getParent(), imageRun, (MImage) object);
res = (XWPFParagraph) imageRun.getParent();
final XWPFParagraph imageParagraph = (XWPFParagraph) imageRun.getParent();
insertMImage(imageParagraph, imageRun, (MImage) object);
res = imageParagraph;
} else {
res = paragraph;
}
Expand Down Expand Up @@ -773,16 +773,20 @@ public XWPFParagraph caseComment(Comment comment) {
* the {@link XWPFRun}
* @param bookmark
* the {@link MBookmark}
* @return the {@link XWPFParagraph} where the bookmark was inserted
*/
private void insertMBookmark(XWPFParagraph paragraph, XWPFRun run, MBookmark bookmark) {
XWPFParagraph newParagraph = (XWPFParagraph) insertFieldRunReplacement(paragraph, run, "").getParent();
private XWPFParagraph insertMBookmark(XWPFParagraph paragraph, XWPFRun run, MBookmark bookmark) {
final XWPFParagraph res = (XWPFParagraph) insertFieldRunReplacement(paragraph, run, "").getParent();

if (bookmark.isReference()) {
bookmarkManager.insertReference(newParagraph, bookmark.getId(), bookmark.getText());
bookmarkManager.insertReference(res, bookmark.getId(), bookmark.getText());
} else {
bookmarkManager.startBookmark(result, newParagraph, bookmark.getId());
insertFieldRunReplacement(newParagraph, run, bookmark.getText());
bookmarkManager.endBookmark(result, newParagraph, bookmark.getId());
bookmarkManager.startBookmark(result, res, bookmark.getId());
insertFieldRunReplacement(res, run, bookmark.getText());
bookmarkManager.endBookmark(result, res, bookmark.getId());
}

return res;
}

/**
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of a query :
[query: .fromHTMLURI('doc.html')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="a" templateFileName="a-template.docx" resultFileName="a-actual-generation.docx" validationFileName="a-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<html>
<head>
</head>
<body>
<table>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
<td>Title 4</td>
<td>Title 5</td>
</tr>
<tr>
<td>cell 1.1</td>
<td>cell 1.2</td>
<td>cell 1.3</td>
<td>cell 1.4</td>
<td>cell 1.5</td>
</tr>
<tr>
<td>cell 2.1</td>
<td>cell 2.2</td>
<td>cell 2.3</td>
<td>cell 2.4</td>
<td>cell 2.5</td>
</tr>
<tr>
<td>cell 3.1</td>
<td>cell 3.2</td>
<td>cell 3.3</td>
<td>cell 3.4</td>
<td>cell 3.5</td>
</tr>
<tr>
<td>cell 4.1</td>
<td>cell 4.2</td>
<td>cell 4.3</td>
<td>cell 4.4</td>
<td>cell 4.5</td>
</tr>
</table>
Text 1 after first table<br/><table>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
<td>Title 4</td>
<td>Title 5</td>
</tr>
<tr>
<td>cell 1.1</td>
<td>cell 1.2</td>
<td>cell 1.3</td>
<td>cell 1.4</td>
<td>cell 1.5</td>
</tr>
<tr>
<td>cell 2.1</td>
<td>cell 2.2</td>
<td>cell 2.3</td>
<td>cell 2.4</td>
<td>cell 2.5</td>
</tr>
<tr>
<td>cell 3.1</td>
<td>cell 3.2</td>
<td>cell 3.3</td>
<td>cell 3.4</td>
<td>cell 3.5</td>
</tr>
<tr>
<td>cell 4.1</td>
<td>cell 4.2</td>
<td>cell 4.3</td>
<td>cell 4.4</td>
<td>cell 4.5</td>
</tr>
</table>
Text 1 after second table<br/><table>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
<td>Title 4</td>
<td>Title 5</td>
</tr>
<tr>
<td>cell 1.1</td>
<td>cell 1.2</td>
<td>cell 1.3</td>
<td>cell 1.4</td>
<td>cell 1.5</td>
</tr>
<tr>
<td>cell 2.1</td>
<td>cell 2.2</td>
<td>cell 2.3</td>
<td>cell 2.4</td>
<td>cell 2.5</td>
</tr>
<tr>
<td>cell 3.1</td>
<td>cell 3.2</td>
<td>cell 3.3</td>
<td>cell 3.4</td>
<td>cell 3.5</td>
</tr>
<tr>
<td>cell 4.1</td>
<td>cell 4.2</td>
<td>cell 4.3</td>
<td>cell 4.4</td>
<td>cell 4.5</td>
</tr>
</table>
Text 3 after third table<br/>
</body>
</html>


0 comments on commit 99030b8

Please sign in to comment.