markdown-transform icon indicating copy to clipboard operation
markdown-transform copied to clipboard

fix(table): handle HTML table captions correctly

Open omda777 opened this issue 10 months ago • 2 comments

Closes #635

This PR fixes incorrect handling of HTML elements in tables during HTML → CommonMark deserialization. It ensures captions are properly parsed, normalized, and emitted as Markdown content preceding the table, while also fixing edge cases related to table headers and whitespace normalization.

Screenshots or Video

Input (HTML with element):

<table>
  <caption>Employee Details</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Role</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>Engineer</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>Designer</td>
    </tr>
  </tbody>
</table>

the output: image

**Employee Details**

| Name | Role |
|---------|---------|
| Alice | Engineer |
| Bob | Designer |

Related Issues

  • Issue #635

Author Checklist

  • [x] Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • [x] Vital features and changes captured in unit and/or integration tests
  • [x] Commits messages follow AP format
  • [ ] Extend the documentation, if necessary
  • [x] Merging to main from fork:branchname

omda777 avatar Jan 13 '26 11:01 omda777

hi @mttrbrts can review PR

omda777 avatar Feb 23 '26 02:02 omda777

Thanks @omda777 for working on this caption handling fix! The approach looks good, but I noticed some issues to address:

Tests Required The PR modifies significant deserialization logic but doesn't include any test coverage. Per repo guidelines, bug fixes must include regression tests. Please add tests for:

  • <caption> element deserialization
  • cleanTableNodes() whitespace normalization
  • Edge case: <tbody> with <th> cells and no <thead>
  • Tables without captions (ensure no regression)

Minor: Code Style The cleanTableNodes function has inconsistent brace placement. Please use the repo's standard style (braces on same line as if/else).

Once tests are added, this should be good to merge. Thanks for contributing! 🙏


This comment was generated by AI on behalf of @mttrbrts.

mttrbrts avatar Apr 26 '26 19:04 mttrbrts