Skip to content

Commit

Permalink
Fixed #484 Add support for thead tag in HTML table.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jun 6, 2023
1 parent df0f6fe commit 31dc437
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ private void walkNodeTree(MList parent, Context context, Node node, Element last
final Context contextCopy = context.copy();
if (node instanceof Element) {
if ("table".equals(node.nodeName())) {
Node tHeader = null;
for (Node child : node.childNodes()) {
if ("thead".equals(child.nodeName())) {
tHeader = child;
break;
}
}
Node tBody = null;
for (Node child : node.childNodes()) {
if ("tbody".equals(child.nodeName())) {
Expand All @@ -471,7 +478,7 @@ private void walkNodeTree(MList parent, Context context, Node node, Element last
}
}
if (tBody != null) {
insertTable(parent, context, tBody);
insertTable(parent, context, tHeader, tBody);
}
} else {
if (UL_TAG.equals(node.nodeName()) || OL_TAG.equals(node.nodeName())) {
Expand Down Expand Up @@ -538,15 +545,25 @@ private void walkChildren(Node node, Context context, MList parent) {
* the parent {@link MList}
* @param context
* the current {@link Context}
* @param node
* the table {@link Node};
* @param header
* the table header {@link Node};
* @param body
* the table body {@link Node};
*/
private void insertTable(MList parent, Context context, Node node) {
private void insertTable(MList parent, Context context, Node header, Node body) {
final MTable table = new MTableImpl();
parent.add(table);
final Map<Integer, Integer> rowSpans = new HashMap<>();
final Map<Integer, List<MCell>> vMergeCopies = new HashMap<>();
for (Node child : node.childNodes()) {
final List<Node> childNodes;
if (header != null) {
childNodes = new ArrayList<>(header.childNodes());
childNodes.addAll(body.childNodes());
} else {
childNodes = new ArrayList<>(body.childNodes());
}

for (Node child : childNodes) {
if ("tr".equals(child.nodeName())) {
final MRow row = new MRowImpl();
table.getRows().add(row);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html>
<header>
</header>
<body>
<table>
<colgroup>
<col style="width: 11.5384%;" />
<col style="width: 11.5384%;" />
<col style="width: 57.6923%;" />
<col style="width: 11.5384%;" />
<col style="width: 7.6925%;" />
</colgroup>
<thead>
<tr>
<th>Hearder 1</th>
<th>Hearder 2</th>
<th>Hearder 3</th>
<th>Hearder 4</th>
<th>Hearder 5</th>
</tr>
</thead>
<tbody>
<tr>
<td><p class="tableblock">cell 2.1</p></td>
<td><p class="tableblock">cell 2.1</p></td>
<td><p class="tableblock">cell 2.3</p></td>
<td><p class="tableblock">cell 2.4</p></td>
<td><p class="tableblock">cell 2.5</p></td>
</tr>
</tbody>
</table>
</body>
</html>

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="table" templateFileName="table-template.docx" resultFileName="table-actual-generation.docx" validationFileName="table-actual-validation.docx"/>

0 comments on commit 31dc437

Please sign in to comment.