question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessibility issue: tables are not outputting <thead> and <th> tags

See original GitHub issue

In Microsoft Word, you can define if you wish your table to contain a < thead > and first column < th > tags through this toolbar:

Image of Word document toolbar

However these settings are being ignored by Mammoth when a word document is being processed. Instead it strips all table headings out and simply outputs a table of basic table cells.

For the following table, I used the settings used in the image above.

Example table

This is the output that I was expecting Mammoth to output:

<table>
    <thead>
        <tr>
            <th>
                <p>Name</p>
            </th>
            <th>
                <p>Number</p>
            </th>
            <th>
                <p>Year</p>
            </td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>
                <p>Thing</p>
            </th>
            <td>
                <p>123</p>
            </td>
            <td>
                <p>2017</p>
            </td>
        </tr>
        <tr>
            <th>
                <p>Other thing</p>
            </th>
            <td>
                <p>458</p>
            </td>
            <td>
                <p>2016</p>
            </td>
        </tr>
    </tbody>
</table>

This is the markup I got though:

<table>
    <tbody>
        <tr>
            <td>
                <p>Name</p>
            </td>
            <td>
                <p>Number</p>
            </td>
            <td>
                <p>Year</p>
            </td>
        </tr>
        <tr>
            <td>
                <p>Thing</p>
            </td>
            <td>
                <p>123</p>
            </td>
            <td>
                <p>2017</p>
            </td>
        </tr>
        <tr>
            <td>
                <p>Other thing</p>
            </td>
            <td>
                <p>458</p>
            </td>
            <td>
                <p>2016</p>
            </td>
        </tr>
    </tbody>
</table>

Mammoth version: v1.4.2 OS: Windows 10 node.js version: 6.9.4

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwilliamsoncommented, Aug 14, 2017

There are two main places you’d need to look at. One is the code that parses the document in lib/docx/body-reader.js. The existing code that handles table headers is probably a good feature to look at for a rough idea of how to implement this. For header rows, you probably want to reuse the same property i.e. isHeader on table rows, plus add a property to handle header columns. You then need to update the conversion to HTML in lib/document-to-html.js. Header rows will already be handled by the existing code, but you’d need to add support for header columns.

Each module should be covered by tests. The test directory structure should mirror the directory structure of the code under test, so hopefully they’re reasonably straightforward to navigate around. Again, looking for the existing support for table headers is probably a good place to start.

0reactions
mwilliamsoncommented, Apr 20, 2019

The Python implementation is fairly similar to the JavaScript implementation, but it’s worth noting that they (should!) have the same level of support for tables.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Acrobat - problems with table <THead> tags for Accessibility
To create a THead tag you would right click on the <Table> Tag in the Tags Panel, select "New" and Type THead, (rather...
Read more >
Tables Tutorial | Web Accessibility Initiative (WAI) - W3C
This tutorial shows you how to apply appropriate structural markup to tables. It includes the following pages:
Read more >
Empty or Missing Table Header - Equalize Digital
An empty table header error means that one of the table headers on your post or page does not contain any text. This...
Read more >
HTML table advanced features and accessibility
The <thead> element must wrap the part of the table that is the header — this is usually the first row containing the...
Read more >
Does putting the <tfoot> tag before <tbody> makes a table ...
In HTML4, tfoot had to appear before tbody , but HTML5 allowed either before or after. Placing it before causes problems for keyboard...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found