Skip to content

feat(export): export the current document as an A4 PDF - #81

Open
project820 wants to merge 3 commits into
mainfrom
feat/pdf-export
Open

project820 wants to merge 3 commits into
mainfrom
feat/pdf-export

Conversation

@project820

@project820 project820 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Adds File > Export as PDF… (⇧⌘E). It writes the current Markdown document to a PDF using the agreed defaults from #79:

  • A4 pages.
  • A fixed light print style, even when the app uses the dark theme.
  • A page number centered in the footer, with no header or other footer content.

Before exporting, the renderer applies any rich-preview edit still waiting for its sync to the Markdown source, the same flush the save path uses. If that sync fails, or saving is blocked during a close, the export stops and writes nothing. The renderer then renders the up-to-date Markdown with the preview's markdown-it configuration. The main process opens a save dialog that defaults to <document name>.pdf next to the document. It prints the HTML in a hidden window with JavaScript disabled, using printToPDF, and saves it with atomicWrite so a failed export leaves no partial file.

The menu label comes from the renderer's five locale dictionaries and is rebuilt when the language changes. The status line also reports progress, success, or failure in all five locales.

Closes #79

Validation

  • New test:pdf-export-e2e (added to CI) boots the app with a long Korean/English document, switches the renderer to the dark theme, and drives the menu path with a stubbed save dialog. It checks four scenarios:
    • Canceling the save dialog writes nothing.
    • Saving produces an 8-page PDF with an A4 MediaBox, and the Markdown file stays byte-identical.
    • An edit typed into the rich preview and exported within the 350 ms sync window reaches the exported HTML. This assertion fails without the flush.
    • The menu item shows the label for the current locale.
  • Inspected the rendered pages: white background, typography that matches the preview, and a page number in the footer.
  • typecheck, test (2442 passed), build, knip, test:security-e2e, test:converter-e2e, test:html-export-direct, test:roundtrip-smoke, and test:close-dialog-smoke all pass. The smoke run covers all 10 scenarios because src/renderer/main.ts changed.
  • npm audit --omit=dev --audit-level=high fails on existing dependency advisories; this PR adds no dependencies.

Adds File > Export as PDF... (Shift+Cmd+E). Renders the Markdown source with the preview's markdown-it config into a fixed light print document, prints it to A4 with a page-number footer in a hidden script-free window, and saves it atomically. Adds a pdf-export e2e runner to CI.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T04:40:52.855952Z 2f66e2c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8789cad141

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/renderer/main.ts Outdated
});

installDocumentLinkBackstop(ctx.preview.el, (url) => void window.api.openExternal(url));
wirePdfExport(window.api, () => ctx.editor.getDoc(), ctx.setStatus);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Flush pending preview edits before exporting

If the user edits the rich preview and immediately invokes Export as PDF, the preview edit can still be waiting in the 350 ms synchronization debounce, but this callback reads CodeMirror directly without calling flushPendingPreviewToSource. The resulting PDF therefore omits edits that are visibly present in the current document; flush the preview into the canonical Markdown before rendering, and fail the export if that synchronization cannot complete.

AGENTS.md reference: AGENTS.md:L14-L14

Useful? React with 👍 / 👎.

…em (#79)

Export now applies DOM-only rich-preview edits before rendering and fails without writing when the source cannot be synchronized. The menu label comes from the renderer's five-locale dictionaries and is rebuilt on locale change. The e2e runner covers both.
index.html ships lang=ko, so <html lang> does not reflect an English renderer locale; read the locale from the localized success status instead.
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.

feat: Markdown 문서 PDF 내보내기

1 participant