Skip to content

fix: convert tables containing bullet lists to Markdown (#6)#7

Merged
aqueeb merged 2 commits into
mainfrom
fix/tables-with-lists-issue-6
Jul 3, 2026
Merged

fix: convert tables containing bullet lists to Markdown (#6)#7
aqueeb merged 2 commits into
mainfrom
fix/tables-with-lists-issue-6

Conversation

@aqueeb

@aqueeb aqueeb commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #6 — Confluence tables whose cells contain a bullet/numbered list were left as raw HTML instead of a Markdown table.

Root cause: pandoc's GFM writer can only place inline, single-line content in pipe-table cells. When a cell holds block-level content (a <ul>/<ol> list), pandoc can't express it as a pipe table and falls back to emitting the entire table as raw HTML. (Hard <br> breaks in a cell trigger the same fallback — which is why the existing code already strips them.)

Fix: In converter/markdown.go, flatten in-cell lists to inline • item / N. item segments before pandoc runs, joined by a @@C2MDBR@@ sentinel. postProcessMarkdown restores the sentinel to a literal <br> as its final step, so pandoc emits a clean pipe table and GitHub still renders line-broken bullets inside the cell. Cells without lists keep their existing space-joined behavior (no regression).

Before

<table>
<tbody>
<tr><th><strong>title 1</strong></th><th><strong>title 2</strong></th></tr>
<tr><td>left side:<ul><li>foo</li><li>bar</li></ul></td><td>right side</td></tr>
</tbody>
</table>

After

| **title 1**                  | **title 2** |
|------------------------------|-------------|
| left side:<br>• foo<br>• bar | right side  |

Tests

  • New unit tests: unordered list, ordered list numbering, list-free cell (regression guard), sentinel→<br>.
  • New end-to-end ConvertHTMLToMarkdown test on the issue's exact table shape (asserts a pipe table, no <table>/<ul>).
  • Full go test ./... passes; gofmt/go vet clean.
  • Verified against the reporter's testpage.doc.

Limitation

Deeply nested sub-lists inside a cell flatten to a single bullet level (items preserved as text, no indentation) — acceptable for typical Confluence tables and noted in a code comment.

🤖 Generated with Claude Code

Confluence table cells containing a bullet or numbered list were left as raw
HTML because pandoc's GFM writer cannot place block-level content in a pipe
table cell and falls back to emitting the entire table as HTML.

Flatten in-cell <ul>/<ol> lists to inline "• item" / "N. item" segments
before pandoc runs, joined by a sentinel that post-processing restores to a
literal <br>. Pandoc then produces a Markdown pipe table and GitHub renders
line-broken bullets inside the cell. Cells without lists keep their existing
space-joined behavior, so there is no regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Aqueeb Qadri <aqueeb@gmail.com>
@codecov-commenter

codecov-commenter commented Jul 2, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
converter/markdown.go 94.11% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Confluence exports place <th> cells inside <tbody> with no <thead>, so pandoc
synthesized an empty header row and demoted the real header into the table
body. Promote the first row into <thead> when it is built from <th> cells so
pandoc emits a proper Markdown table header.

Also fix a latent normalization bug where the "<th[^>]*>" attribute-stripping
regex matched "<thead>" (which shares the "<th" prefix) and corrupted explicit
table headers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Aqueeb Qadri <aqueeb@gmail.com>
@aqueeb
aqueeb merged commit c78b25c into main Jul 3, 2026
5 checks passed
@aqueeb
aqueeb deleted the fix/tables-with-lists-issue-6 branch July 3, 2026 00:51
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.

Tables sometimes still in HTML

2 participants