Skip to content

dsh-editor: Export the rendered Markdown to a PDF on the Desktop - #21

Merged
vecnode merged 1 commit into
mainfrom
feat/editor-export-pdf
Nov 28, 2026
Merged

vecnode merged 1 commit into
mainfrom
feat/editor-export-pdf

Conversation

@vecnode

@vecnode vecnode commented Nov 28, 2026

Copy link
Copy Markdown
Owner

What this adds

The right bar's rendered Markdown view already had an Edit pill. It now has an Export PDF pill to its left, the same size, which saves the Markdown file as a PDF on the machine's Desktop.

  • Clicking it prints the file on disk (the preview reads disk, so what is exported is what is shown).
  • The client sends only {session, path}; the Node half reads the file with the same containment check as every other read, so a tab cannot make the export read something else.
  • The PDF lands in the host's real Desktop (~/Desktop, a OneDrive-redirected Windows profile, or an XDG_DESKTOP_DIR folder), resolved per request. DSH_EDITOR_PDF_DIR redirects it.
  • An export never replaces an existing file: a second one is name (2).pdf.
  • The button reports Exporting…, then Saved ✓ (path in the tooltip), or Export failed with the route's reason.

How it works

packages/dsh-editor/lib/export-pdf.js renders the Markdown to one self-contained HTML page (Markdown subset, GFM tables, fenced code, reference links, task lists, block-level authored HTML, local images as data URIs, print CSS) and asks the Chromium-family browser already on the machine to --print-to-pdf it in a throwaway profile with a resolver that fails every non-loopback name. No bundled binary, no npm dependency, no network egress:

  • Local images are embedded; remote http(s) images are not fetched and keep their alt text.
  • <details> is drawn open (a PDF has nothing to click).
  • Chinese and other scripts print through the browser's own font fallback.
  • No browser installed → 503 NO_ENGINE with the install hint, nothing written.

Route: POST /api/dsh-editor/export-pdf → { ok, name, path, bytes }.

To try it

  1. Restart npx @deepseek-ai/dsh web (the Node route registers at boot), then hard-refresh the page.
  2. Open a .md file in the right bar, switch to Preview.
  3. Click Export PDF — it sits left of Edit and the file appears on the Desktop.

Verification

  • node scripts/checks/check-client-bundles.mjs — button order (Export PDF before Edit), shared size rule, injected handler; whole suite passes.
  • node scripts/checks/check-node-routes.mjs — renderer assertions (headings, tables, code, Chinese, embedded local image, remote image as alt text, fenced <script> as text, container, open <details>), route validation, and the end-to-end route against a scratch Desktop (real %PDF-, second export doc (2).pdf, binary refused, both files kept); whole suite passes.
  • node scripts/checks/check-no-secrets.mjs — OK.
  • node scripts/checks/check-scripts.mjs — OK.

The printed PDF was also inspected page-by-page: typography, bullets, tables, code, the centred README header, an embedded screenshot and open <details> all render.

Version

dsh-editor 0.1.0-alpha.15 → 0.1.0-alpha.16 (manifest and package.json in step).

The right bar's rendered Markdown body carried only "Edit". It now carries
"Export PDF" to its left, the same size: one click prints the file on disk to
~/Desktop/<name>.pdf.

The client sends only {session, path}; the Node half reads the file itself
(containment-checked like every read), renders it as one self-contained HTML
page and asks the Chromium-family browser already on the machine to print it
with --print-to-pdf. Local images are embedded as data URIs, remote images are
left as alt text (no egress), <details> is drawn open, and the Desktop is
resolved per request (OneDrive-redirected / XDG aware). An export never
replaces an existing file: a second one is "name (2).pdf".

The route is POST /api/dsh-editor/export-pdf; a host without a browser answers
503 NO_ENGINE with the install hint, and DSH_EDITOR_PDF_DIR redirects the
folder.

Checks: check-client-bundles.mjs (button order and the shared size rule),
check-node-routes.mjs (the renderer, the route end to end against a scratch
Desktop, no-overwrite naming, a binary refusal), check-no-secrets.mjs and
check-scripts.mjs. The printed PDF was inspected: headings, tables, code,
Chinese, a local image and open <details> all render.
@vecnode
vecnode merged commit 1ee8a47 into main Nov 28, 2026
1 check passed
@vecnode
vecnode deleted the feat/editor-export-pdf branch November 28, 2026 10:15
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