Skip to content

feat(app): Markdown preview panel next to the terminal - #57

Merged
arifintahu merged 12 commits into
mainfrom
feat/markdown-preview
Nov 23, 2026
Merged

arifintahu merged 12 commits into
mainfrom
feat/markdown-preview

Conversation

@arifintahu

@arifintahu arifintahu commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What and why

Adds a Markdown preview panel next to the terminal (closes #55). Reading a README or runbook with cat prints raw source; now the file can be shown rendered beside the shell.

  • Open it: Ctrl+click a .md name in the output, "Preview Markdown file…" in the command palette, or Ctrl+Shift+M. A setting, off by default, opens it after cat README.md finishes (Git Bash, WSL, pwsh; a pipe, glob, variable or second file is ignored).
  • What it shows: GitHub-flavoured Markdown (tables, task lists, strikethrough, autolinks), highlighted code blocks (15 languages), heading anchors, local relative images, relative .md links with back/forward. Remote images are replaced by a note.
  • Live reload: the panel refreshes when the file changes (modified-time polling, only while the tab is active and the window focused). A file that vanishes keeps the last render with a note and recovers when it returns, which covers editors that save by rename.
  • Shape: Rust only reads files and maps shell paths (Git Bash /d/x, WSL /mnt/d/x and \\wsl.localhost\<distro>, pwsh) to Windows paths: file_preview, file_preview_image, file_preview_stat, preview_resolve, no new crates. The frontend renders with marked + DOMPurify into a DOM fragment (never {@html}) and loads all of it, plus highlight.js, on first use. The panel is a column beside a stable terminal wrapper in TabPane, outside the terminal split model, so the terminals do not remount when it opens. It is not saved in session.json.

Security: Markdown from a cloned repo is untrusted. Output is sanitized before it is inserted (hostile tags and attributes, image maps, media, SVG, form controls, javascript: and data: links are all removed), the CSP is unchanged, and local images load as data: URLs within a 20 MB budget. Terminal output can forge a path or the OSC 7 folder, and a UNC read makes Windows start SMB auth, so only \\wsl.localhost\ network paths are ever read.

How you checked it

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings: clean
  • cargo test: 133 passed (new: path resolution table, file commands and caps, config default)
  • pnpm turbo check test build: pass, 353 Vitest tests (new: sanitizer vectors, links, images, poller with fake timers, cat parser, jsdom component tests for the body and panel)
  • pnpm version:check: pass
  • A fresh whole-branch review found no critical issues; its four important findings (image-map click navigating the window, sanitizer allow-list, image loading and budget, reload with unchanged text) are fixed with tests.

Measured:

main this branch
Main index-*.js (raw / gzip) 583,408 / 159,141 B 592,034 / 162,374 B (+1.5%)
Release .exe 16,706,048 B 16,899,584 B (+1.2%; assets are embedded uncompressed)

New lazy chunks, gzip: markdown renderer about 33 KB (marked 16, DOMPurify 12, panel 4.5), highlight.js core plus 15 languages about 24 KB. Nothing from them loads until the first preview.

Render time in Chromium (dev build): a prose-heavy 200 KB document takes about 40–65 ms and a 1 MB one about 190 ms. A dense synthetic 200 KB document (887 tables and 887 code blocks) takes about 270 ms, over the 100 ms goal; if real documents are ever that dense, rendering in Rust is the follow-up.

Live test in the real app

Run as a dev build (cargo tauri dev) and driven through the WebView2 debug port against a folder of test documents, on Git Bash:

  • Open: Ctrl+click on README.md in ls output opens the panel (/d/... resolved to a Windows path); a plain click does nothing. The terminal refits (167 to 97 columns) and keeps its scrollback, and refits back when the panel closes with Ctrl+Shift+M.
  • Rendering: table, task list, 23 highlighted code spans, heading ids, local images (including a <picture>) as data URLs, the remote image replaced by a note, the <map>/<area> stripped. Status bar shows "Preview: README.md · 899 B". No CSP or console errors during the whole run (only the dev server's favicon 404).
  • Links: a relative .md link opens in the same panel with working Back/Forward; the .pdf link gives a toast; a click on an image with usemap does not navigate the window; an #anchor link scrolls a long document.
  • Live reload: an edit, an atomic rename-save, a delete (note shown, last render kept, live dot grey) and a restore all behave; scroll position is kept across a reload; a touch with identical text does not re-render.
  • Layout: split tab plus panel gives two 355 px terminals and a 480 px panel; the panel shows only in the tab that opened it.
  • Opt-in cat: turned on through the Settings UI. cat README.md opens the panel about 110 ms after Enter; cat a.md | head, two files, a glob and a redirect do nothing.
  • Limits: a 1.1 MB file gives "File is over 1 MB, too large to preview"; a quoted name with spaces gives "File not found" (documented limit).
  • Throughput: cat of a 16 MB file takes 1.74 to 1.81 s with the panel closed and 1.37 to 1.42 s with it open (the narrower terminal renders fewer cells). No regression.

Known gaps

  • Not yet checked by hand: WSL and pwsh paths, the Ctrl+Shift+M file dialog (a native dialog), and a <picture> whose <source> points at a dark-mode image on a real display. One cat README.md right after closing Settings did not open the panel; it did not reproduce in five more tries, and my own test command had also used &&, so it is probably my test harness, but I could not rule out a timing issue.

  • Ctrl+click finds names without spaces on a single line; output from an earlier folder may not resolve; ~ is not supported in WSL; auto-open fires when the command ends (the next prompt), not while it prints.

  • Smaller deferred items from the review: a transient read failure can leave a stale note, an empty working folder resolves against the root, a failed auto-open toasts on top of the shell's own error, docs/a.md#section does not scroll to the section, narrow tabs (< 480 px) squeeze the terminal below 240 px, and a symlink to a UNC path or reserved names like CON.md are unverified edge cases.

  • cargo fmt --check, cargo clippy -- -D warnings and cargo test pass

  • pnpm turbo check test build and pnpm version:check pass

  • Bug fixes have a test that failed before the fix

  • No secrets, personal paths or machine names in the diff

  • Docs and CHANGELOG.md updated if behaviour changed

Maps Git Bash, WSL and pwsh paths to Windows paths. Network paths other than WSL's own never resolve, since terminal output can forge a path and a UNC read starts SMB auth.
file_preview, file_preview_image, file_preview_stat and preview_resolve, with a 1 MB document cap, a 5 MB image cap, extension allowlists and no network paths.
Per-tab preview history with back and forward, size and error helpers, and a paneContext lookup. The state is not saved in session.json.
marked and DOMPurify are imported on first use. Hostile HTML, javascript: and data: links, styles, forms and extra inputs are stripped; heading ids follow GitHub's rules.
Relative links resolve against the document, only Markdown opens in the panel, remote images are replaced by a note, and local images load as data URLs within a 20 MB budget.
A right-hand column in the tab, loaded on first use. The terminals sit in a stable wrapper so they do not remount when the panel opens. Includes a draggable divider, back/forward, links, images and a status-bar item.
highlight.js core plus 15 languages, loaded only when a document has a fenced block with a known language. Token colours use the theme variables.
Polls the file's modified time about once a second while the tab is active and the window focused. A missing file keeps the last render with a note and recovers when the file returns, which covers editors that save by rename.
Ctrl+click on a .md name in the output, the Preview Markdown file command, or Ctrl+Shift+M. The path is resolved for the pane's shell and folder, and a file that does not read is a toast, not an empty panel.
New setting, off by default. After a command like cat README.md finishes, the file opens in the preview. A pipe, redirect, glob, variable or a second file is ignored.
CHANGELOG entry, README feature, and the CLAUDE.md file map, IPC table and the two rules that matter: terminals must not remount, and Markdown is untrusted.
Review findings: an image-map area could navigate the window and the sanitizer let through media, srcset, svg and form controls; images are now filled in after the text is shown, with a budget that stops reading, a per-render cache and cancellation; a touch with unchanged text no longer re-renders.
@arifintahu arifintahu added the enhancement New feature or request label Nov 23, 2026
@arifintahu
arifintahu merged commit 59233fc into main Nov 23, 2026
4 checks passed
@arifintahu
arifintahu deleted the feat/markdown-preview branch November 23, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(app): Markdown preview pane next to the terminal

1 participant