Skip to content

fix(table): Fix header separator logic and add tests for HTML table conversion - #463

Merged
shinya merged 8 commits into
Bokuchi-Editor:mainfrom
tanahiro2010:fix/table_bugs
Aug 2, 2026
Merged

fix(table): Fix header separator logic and add tests for HTML table conversion#463
shinya merged 8 commits into
Bokuchi-Editor:mainfrom
tanahiro2010:fix/table_bugs

Conversation

@tanahiro2010

Copy link
Copy Markdown
Contributor

This pull request fixes a bug in the table-to-Markdown conversion logic where an empty leading row in an HTML table or CSV/TSV input would cause the Markdown header separator row to be omitted. The fix ensures that the separator is always inserted after the first non-empty row, regardless of any skipped empty rows. A new test case is also added to verify this behavior.

Bug fix for header separator logic:

  • src/utils/tableConverter.ts: The logic for inserting the Markdown header separator row now checks if the current row is the first emitted (non-empty) row, rather than relying on the loop index. This prevents empty leading rows from breaking the output. [1] [2]

Test coverage:

Copilot AI review requested due to automatic review settings August 1, 2026 02:26
@tanahiro2010 tanahiro2010 changed the title Fix header separator logic and add tests for HTML table conversion fix: Fix header separator logic and add tests for HTML table conversion Aug 1, 2026
@tanahiro2010 tanahiro2010 changed the title fix: Fix header separator logic and add tests for HTML table conversion fix(table): Fix header separator logic and add tests for HTML table conversion Aug 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Markdown header-separator emission in the table conversion utilities when leading empty rows/lines are skipped, ensuring the separator is inserted after the first emitted row.

Changes:

  • Update htmlTableToMarkdown to insert the header separator after the first non-empty <tr> that is actually output.
  • Update convertTsvCsvToMarkdown to insert the header separator after the first non-empty line that is actually output.
  • Add an HTML regression test covering a leading empty <tr>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/utils/tableConverter.ts Fixes header-separator insertion to key off the first emitted row, not the raw loop index, for both HTML and TSV/CSV conversion paths.
src/utils/__tests__/tableConverter.test.ts Adds a regression test for HTML tables with a leading empty row (and includes commentary updates needing cleanup).
Suppressed comments (1)

src/utils/tests/tableConverter.test.ts:156

  • This inline note says the assertion "currently fails", but with the header-separator fix applied this should now pass. Leaving it in will confuse future readers/debugging.
    expect(lines[1]).toContain('---'); // currently fails: lines[1] is '| 1 | 2 |'

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/__tests__/tableConverter.test.ts Outdated
Comment thread src/utils/tableConverter.ts
tanahiro2010 and others added 6 commits August 1, 2026 11:30
Remove references to old loop indices (i === 0 / i === 1) from the T-TC-22 
and line 156 comments, updating them to describe the regression context instead.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…version

Pins the header-separator behavior for an empty leading line, the
TSV/CSV counterpart to the empty-leading-row case fixed for HTML
tables (T-TC-22), so a future change to trimming/loop logic can't
silently drop the separator row again.
@shinya

shinya commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your assistance.
Due to an update to the library, there were some parts that needed to be changed. I’ve made minor corrections to those sections.
I’ll incorporate these changes as a pull request.

@shinya
shinya merged commit c9836f1 into Bokuchi-Editor:main Aug 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants