Skip to content

Commit

Permalink
add test, update check for table
Browse files Browse the repository at this point in the history
  • Loading branch information
goose-life committed Aug 17, 2024
1 parent 8011656 commit df287d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ export function htmlToAkn (html) {
}

// add missing rows and cells to tables
// TODO: better check for this?
if (html.tagName === "TABLE") {
if (xml.firstChild.tagName === "table") {
fixTable(xml.firstChild);
}

Expand Down
36 changes: 36 additions & 0 deletions tests/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,40 @@ describe('htmlToAkn', () => {
const akn = convert(`<div><div>first</div><div>second</div></div>`, true);
expect(akn).to.eql(`<p xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0"><p>first</p><p>second</p></p>`);
});

it('should insert missing rows and cells as required to get a clean table matrix', () => {
const akn = convert(`<table id="hcontainer_1__table_1" data-eid="hcontainer_1__table_1">
<tbody><tr>
<th><span id="hcontainer_1__table_1__p_1" data-eid="hcontainer_1__table_1__p_1">Heading 1</span></th>
<th><span id="hcontainer_1__table_1__p_2" data-eid="hcontainer_1__table_1__p_2">Heading 2</span></th>
</tr>
<tr>
<td class="akn-td" rowspan="5" colspan="1"><span id="hcontainer_1__table_1__p_3" data-eid="hcontainer_1__table_1__p_3">&nbsp;</span></td>
<td class="akn-td" rowspan="2" colspan="1"><span id="hcontainer_1__table_1__p_4" data-eid="hcontainer_1__table_1__p_4">&nbsp;</span></td>
</tr>
<tr><td class="akn-td"><span id="hcontainer_1__table_1__p_5" data-eid="hcontainer_1__table_1__p_5">&nbsp;</span></td></tr>
<tr>
<td class="akn-td"><span id="hcontainer_1__table_1__p_6" data-eid="hcontainer_1__table_1__p_6">Content 1</span></td>
<td class="akn-td"><span id="hcontainer_1__table_1__p_7" data-eid="hcontainer_1__table_1__p_7">Content 2</span></td>
</tr>
</tbody></table>`);
expect(akn).to.eql(`<table xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0" eId="hcontainer_1__table_1">
<tr> <th><p>Heading 1</p></th> <th><p>Heading 2</p></th> <td/></tr>
<tr> <td class="akn-td" rowspan="5" colspan="1"><p/></td> <td class="akn-td" rowspan="2" colspan="1"><p/></td> <td/></tr>
<tr>
<td class="akn-td">
<p/>
</td>
</tr>
<tr> <td class="akn-td"><p>Content 1</p></td> <td class="akn-td"><p>Content 2</p></td> </tr>
<tr>
<td/>
<td/>
</tr>
<tr>
<td/>
<td/>
</tr>
</table>`);
});
});

0 comments on commit df287d2

Please sign in to comment.