Skip to content

feat(export): add Markdown and HTML result export formats - #1567

Merged
cevheri merged 2 commits into
libredb:mainfrom
koraysrn:feat/1532-export-markdown-html
Oct 6, 2026
Merged

cevheri merged 2 commits into
libredb:mainfrom
koraysrn:feat/1532-export-markdown-html

Conversation

@koraysrn

@koraysrn koraysrn commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Markdown and HTML result export formats to both shells (Studio.tsx and
StudioWorkspace.tsx). Both formats follow the shared value contract of the existing CSV
exporter, so a value that appears one way in the grid and the CSV reads the same way in the
Markdown table and the HTML table.

Closes #1532

What changed

  • New writers:
    • src/lib/export/markdown.ts renders a pipe table with a header row and a --- separator row.
    • src/lib/export/html.ts renders a complete standalone document: a <table> inside a minimal
      HTML shell with embedded CSS.
  • ResultExportFormat gains markdown and html. Both are text formats, so they use the existing
    ResultExportFile shape and are written through downloadText.
  • BottomPanel.tsx offers both formats in the Export menu and in the Copy-to-clipboard menu.
  • Studio.tsx and StudioWorkspace.tsx keep one shared buildExportSource per shell, so masking
    and agent-artifact hydration apply to the new formats exactly as they apply to CSV, JSON and the
    SQL formats.

Value rendering

Both writers reuse the shared cell contract (renderValue in src/lib/export/csv.ts):

  • null and undefined become an empty cell.
  • Date values become their ISO string.
  • Binary values become the same \x hex the grid and CSV show.
  • Objects become jsonText, which is bigint-safe and cycle-safe.
  • Everything else becomes String(value).

Escaping

  • Markdown escapes \ and | in every cell and header cell, and replaces \n and \r with
    <br> so a cell value cannot break the table row.
  • HTML escapes &, <, >, " and ' in every cell and header cell.

Empty results

  • No columns: empty output for both formats.
  • Columns known but no rows: the header row is still written.

Tests

  • tests/unit/lib/export/markdown.test.ts (17 tests): escaping, header and separator rows,
    newline handling and the empty-result matrix.
  • tests/unit/lib/export/html.test.ts (14 tests): entity escaping, the standalone document shape
    and the empty-result matrix.
  • tests/unit/lib/export/result-export.test.ts gains Markdown and HTML integration coverage
    through buildResultExport.
  • tests/unit/components/bottom-panel-formats.test.ts pins the shared format list.
  • tests/components/studio/bottom-panel-export-formats.test.tsx (13 tests) pins the Export and
    Copy menu items across dialects.

Verification

  • bun run typecheck: clean
  • bun run lint: 0 errors
  • bun run knip: clean
  • bun run build: succeeds
  • Changed unit and component tests pass (603 tests across the export and shell suites)

@koraysrn
koraysrn force-pushed the feat/1532-export-markdown-html branch from c288718 to c073e0f Compare October 6, 2026 19:59
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…ats in FEATURES.md

Each line break in a Markdown cell becomes its own <br>, so a blank line inside a value survives. FEATURES.md now names Markdown and HTML among the export formats and among those kept while masking applies.

@cevheri cevheri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this works well in both shells and the escaping holds up. I pushed a small commit: FEATURES.md now lists Markdown and HTML, and a blank line inside a cell keeps its own
.

@cevheri
cevheri merged commit f72fbcd into libredb:main Oct 6, 2026
23 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.

Export query results as Markdown and HTML

2 participants