Repository navigation
dsh-editor: Export the rendered Markdown to a PDF on the Desktop - #21
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
{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.~/Desktop, a OneDrive-redirected Windows profile, or anXDG_DESKTOP_DIRfolder), resolved per request.DSH_EDITOR_PDF_DIRredirects it.name (2).pdf.Exporting…, thenSaved ✓(path in the tooltip), orExport failedwith the route's reason.How it works
packages/dsh-editor/lib/export-pdf.jsrenders 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-pdfit in a throwaway profile with a resolver that fails every non-loopback name. No bundled binary, no npm dependency, no network egress:http(s)images are not fetched and keep their alt text.<details>is drawn open (a PDF has nothing to click).503 NO_ENGINEwith the install hint, nothing written.Route:
POST /api/dsh-editor/export-pdf→{ ok, name, path, bytes }.To try it
npx @deepseek-ai/dsh web(the Node route registers at boot), then hard-refresh the page..mdfile in the right bar, switch to Preview.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 exportdoc (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-editor0.1.0-alpha.15 → 0.1.0-alpha.16 (manifest and package.json in step).