Skip to content

Add markdown export functionality with PDF support - #10

Merged
Waterkyuu merged 11 commits into
mainfrom
feat/typst-to-markdown
May 3, 2026
Merged

Add markdown export functionality with PDF support#10
Waterkyuu merged 11 commits into
mainfrom
feat/typst-to-markdown

Conversation

@Waterkyuu

Copy link
Copy Markdown
Owner

Introduce a markdown export menu that allows users to download content as Markdown or PDF. Implement server-side PDF generation and refactor the export process to enhance performance and maintainability. Ensure comprehensive testing for all new features and fixes.

Waterkyuu and others added 11 commits May 1, 2026 23:35
- Add export dropdown to markdown preview with PDF and Markdown actions

- Add markdown export helpers for blob download and printable PDF window

- Cover markdown export helpers and preview menu interactions with tests

- Mock markdown ESM plugins in round artifact test to keep Jest compatible

Co-authored-by: Codex <noreply@openai.com>
- Replace print-window PDF export with html2canvas plus jsPDF direct save

- Capture the rendered markdown preview DOM so markdown-preview.css styling is preserved visually

- Paginate rendered canvases into A4 PDF pages

- Disable repeated PDF export clicks while rendering

- Add focused tests for canvas rendering, PDF pagination, and async preview export

Co-authored-by: Codex <noreply@openai.com>
- Render markdown PDFs from an isolated A4-width clone instead of the live preview panel
- Add printable page margins and scale canvas slices to the PDF printable area
- Embed URL-based images as data URLs before html2canvas captures the export clone
- Strip unsupported lab/lch/oklch/color functions from export-only styles to avoid html2canvas parse failures
- Cover A4 sizing, image embedding, and color sanitization in markdown export tests

Co-authored-by: Codex <noreply@openai.com>
- Add an html2canvas onclone hook for markdown PDF export
- Force cloned html and body backgrounds to safe RGB-compatible colors before parsing
- Re-run export subtree color sanitization inside the cloned document
- Cover clone document lab() background regression in markdown export tests

Co-authored-by: Codex <noreply@openai.com>
- map rehype-katex, rehype-raw, remark-gfm, and remark-math to a shared Jest mock so Linux CI does not try to parse ESM-only packages from node_modules
- remove per-test inline plugin mocks now that the Jest config owns this compatibility layer
- rename __mocks__ files to kebab-case and update moduleNameMapper paths for naming consistency
- keep react-markdown test doubles focused on rendered content while centralizing plugin stubbing in one place

Verification:
- pnpm test ✅
- pnpm build ✅
- pnpm check ⚠️ fails on pre-existing Biome formatting drift in biome.json, app/chat/components/markdown-preview-panel.tsx, lib/markdown-export.ts, and lib/markdown-export.test.ts

Co-authored-by: Codex <noreply@openai.com>
- add a Node.js route handler for markdown-to-pdf export
- add a Chromium-backed PDF service using puppeteer-core and @sparticuz/chromium-min
- render markdown, KaTeX, and Mermaid into print HTML before generating the PDF
- extend the Jest environment for route testing and document required export env vars

Verification:
- pnpm test -- lib/markdown-export/pdf-service.test.ts app/api/export/markdown/pdf/route.test.ts
- pnpm exec biome check lib/markdown-export/pdf-export-schema.ts lib/markdown-export/pdf-renderer.tsx lib/markdown-export/pdf-service.ts lib/markdown-export/pdf-service.test.ts app/api/export/markdown/pdf/route.ts app/api/export/markdown/pdf/route.test.ts jest.setup.ts

Co-authored-by: Codex <noreply@openai.com>
- replace the client pdf helper with a POST-based markdown export flow
- update the markdown preview panel to send source markdown instead of a live DOM node
- rewrite markdown export tests around API download behavior rather than html2canvas rendering

Verification:
- pnpm test -- lib/markdown-export.test.ts app/chat/components/markdown-preview-panel.test.tsx
- pnpm exec biome check --write lib/markdown-export.ts lib/markdown-export.test.ts app/chat/components/markdown-preview-panel.tsx app/chat/components/markdown-preview-panel.test.tsx

Co-authored-by: Codex <noreply@openai.com>
- remove html2canvas and jspdf dependencies after switching markdown PDF export to the server route
- update the server renderer to use a runtime react-dom/server import so the Next.js route builds cleanly
- format biome.json so pnpm check passes again

Verification:
- pnpm test
- pnpm build
- pnpm check

Co-authored-by: Codex <noreply@openai.com>
- collapse markdown pdf export onto the SnapDOM-based client pipeline
- remove the split server/snapdom export menu in the markdown preview panel
- update markdown export tests to target the SnapDOM PDF flow

Verification:
- pnpm test -- lib/markdown-export.test.ts app/chat/components/markdown-preview-panel.test.tsx
- pnpm exec biome check lib/markdown-export.ts lib/markdown-export.test.ts app/chat/components/markdown-preview-panel.tsx app/chat/components/markdown-preview-panel.test.tsx

Co-authored-by: Codex <noreply@openai.com>
- remove the markdown PDF route, renderer, schema, and Chromium service files
- drop puppeteer-core and @sparticuz/chromium-min after choosing SnapDOM as the only PDF path
- remove the server-export environment variables from .env.example

Verification:
- pnpm test
- pnpm build
- pnpm check

Co-authored-by: Codex <noreply@openai.com>
- delete the undici-based Headers/Request/Response polyfill that was crashing in CI
- keep the stream, encoder, and worker polyfills that the test environment still needs
- replace the default fetch mock headers with a lightweight get() stub so tests stay decoupled from undici internals

Verification:
- pnpm test -- hooks/use-chat.test.ts lib/chat/workspace-hydration.test.ts app/chat/components/markdown-preview-panel.test.tsx
- pnpm test
- pnpm exec biome check jest.setup.ts

Co-authored-by: Codex <noreply@openai.com>
@Waterkyuu
Waterkyuu merged commit 60ca9ec into main May 3, 2026
1 check 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.

1 participant