Skip to content

feat(editor): add Edit, Split and Read views for Markdown files - #51

Merged
Ferdinand99 merged 3 commits into
mainfrom
feat/markdown-view
Nov 20, 2026
Merged

Ferdinand99 merged 3 commits into
mainfrom
feat/markdown-view

Conversation

@Ferdinand99

@Ferdinand99 Ferdinand99 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Markdown tabs (.md, .markdown, .mdx, or any tab set to Markdown) get three views:

  • Edit: the editor, as before.
  • Split: editor on the left, rendered document on the right, updated while typing, scrolling together both ways.
  • Read: the rendered document only; the editor is hidden and read-only, and commands that change the text are refused.

A small Edit | Split | Read switch sits in the status bar for Markdown tabs only. Ctrl/Cmd+Shift+V toggles Read and Ctrl/Cmd+K V toggles Split (as in VS Code); in other tabs those keys go to the editor as before. Three palette commands. Each tab remembers its view, stored in the session (mdView, optional, older sessions load as Edit).

Rendering

  • markdown-it 15.0.3: CommonMark plus GitHub tables, task lists (disabled checkboxes), strikethrough and autolinks (also www.), heading anchors.
  • Code blocks coloured with the editor's own Lezer grammars and HighlightStyle, so they follow the theme.
  • Light and dark theme from the design tokens (src/styles/markdown.css, documented in docs/design-system.md).
  • Large files: parsing runs in a worker (only the newest request; restarted when one parse takes over 5 s). The document is rendered in content-defined chunks; large lists and tables are split between items and rows (ordered lists continue with start, tables keep the header once and share fixed column widths). Only changed chunks are sanitised and swapped in, one by one in short slices; chunks out of sight use content-visibility, and scroll sync reads chunk boxes, not every block. Renders wait for a pause in typing.
  • markdown-it, DOMPurify and the highlighter load on first use, not at start-up.

Safety

  • All HTML goes through DOMPurify 3.4.17 (HTML profile only). Removed: scripts, event handlers, frames, objects, forms and controls, media, SVG/MathML, <style>/style, <base>/<meta>/<link>, srcset, target, tabindex, etc. id/name get a user-content- prefix; class keeps only the renderer's own names; data-md-* from the file is dropped. The pane uses contain: layout paint.
  • Backend-enforced rules. Four commands, each takes the document path and refuses paths the backend did not open or save itself:
    • md_local_image: files inside the document's folder only (canonical path check; no .., absolute paths, drive letters, :, symlinks or junctions out); image types; 16 MB, enforced while reading.
    • md_allow_remote: shows a native confirmation dialog from Rust and records the yes per document until the app quits.
    • md_remote_image: refuses without that yes. https only; names resolved by the app and every local/private address dropped before connecting (loopback, private, link-local, CGNAT, multicast, reserved; IPv6 ::/96, ::ffff:0:0/96, 64:ff9b::/96, 2002::/16, fec0::/10, fc00::/7, fe80::/10), so the connection goes only to checked addresses, on every redirect too (at most 5). No proxy, no cookies, no Referer, a generic User-Agent; image content types only; 16 MB with or without Content-Length; 20 s.
    • open_external: http, https, mailto (only to, cc, bcc, subject, body; never attach).
  • Links never navigate the window: web links go through open_external; relative .md links open in a tab (path and fragment kept apart, UNC roots respected, : refused); #anchors scroll; everything else is refused.

CSP: unchanged. Images reach the page as data: URLs (already allowed by img-src 'self' data:); the worker is a same-origin script file (default-src 'self'). No new capability or plugin for the webview. docs/markdown-view.md and the security review describe the four commands and their guards.

Dependencies

  • npm: markdown-it 15.0.3 and dompurify 3.4.17, pinned exactly, both released more than two weeks ago (transitive versions resolved with --before).
  • Rust: open 5.4.5 (with is-wsl, is-docker) to open links. reqwest and rustls are used with the same features as the updater (rustls-no-provider + ring), so no other new crates; url and base64 were already in the tree.
  • THIRD-PARTY-NOTICES regenerated. argparse (PSF-2.0), which markdown-it only imports in its command-line tool, is listed under the new npmNotShipped in notices-extra.json with its reason instead of widening the licence allowlist; a unit test checks that markdown-it's library entry does not import it, and stale entries fail the script.

Tests

  • Rust core (mdassets): traversal, absolute paths, drive letters, symlinks (and a Windows junction test), size; the private address ranges; resolved-address filtering; redirect rules; the size cap; mailto fields; the document gate (unknown documents and missing consent refused).
  • Rust (src-tauri/src/mdfetch.rs), against a local HTTP server: images and SVG as data URLs, non-image and missing content types refused, the cap without Content-Length, the time limit, names resolving to the local network, redirects to private names, literals, another scheme or file:, redirect loops.
  • Vitest: renderer (GFM, chunk stability, split lists and tables, 1 MB parse), sanitiser (scripts, onerror, javascript:/data:/file: links, remote image gating, local paths, forbidden elements, class filter, mXSS payloads, HTML across chunks), links (:, UNC, %23), views, chords, per-tab memory and session, the argparse not-shipped check (every script of markdown-it and its dependencies).
  • Playwright (Chromium and WebKit, the real front end under the app's CSP, stubbed backend): views, switch, shortcuts, per-tab memory and session, no script execution, consent before any remote request, link handling, and 1 MB documents (many sections, one long list, one long table) with the pause during the render after an edit asserted under 300 ms.

Not in this round

Mermaid, math, PDF export, editing inside the rendered view, a resizable split handle for the Markdown split, and a screenshot (the docs screenshots come from real Linux builds).

Markdown tabs can now be shown as the editor only (Edit), the editor with the
rendered document beside it (Split, updated while typing, scrolling together)
or the rendered document only (Read, not editable). A small Edit | Split | Read
switch in the status bar appears for Markdown tabs; Ctrl/Cmd+Shift+V toggles
Read and Ctrl/Cmd+K V toggles Split, as in VS Code, and both are in the
command palette. Each tab remembers its view and the session restores it.

Rendering uses markdown-it 15.0.3 (CommonMark plus GitHub tables, task lists,
strikethrough and autolinks) and DOMPurify 3.4.17. Code blocks are coloured
with the editor's own grammars and theme. Parsing runs in a worker and only
the changed part of the document is sanitised and replaced, so a 1 MB file
stays responsive in Split.

Safe by default: raw HTML is sanitised (no scripts, handlers, frames, forms,
styles or SVG; class names limited to the renderer's own), remote images load
only after "Show images" for that document and are downloaded by the backend
(public https hosts, image types, 16 MB), local images are read by the backend
only from the document's folder (no traversal or symlinks out), links open in
the system browser (http, https and mailto only) or, for .md files, in a tab.
The content security policy is unchanged: everything reaches the page as
data: URLs, which it already allows.

New Rust dependency: open 5.4.5 (with is-wsl and is-docker). reqwest and
rustls are used with the same features as the updater, so no new crates come
in for downloads. argparse, which markdown-it only uses in its command-line
tool, is left out of the notices with a recorded reason.

Strings are added in all 26 interface languages. Tests cover the renderer,
the sanitiser, link and image rules, path traversal in the backend, view
switching, per-tab memory and the session, and a Playwright suite runs the
real front end under the app's CSP in Chromium and WebKit.
Remote images: names are resolved by the app and every address on this
computer or the local network is dropped before connecting (loopback,
private, link-local, CGNAT, multicast, reserved, and IPv6 ::/96,
::ffff:0:0/96, 64:ff9b::/96, 2002::/16, fec0::/10, fc00::/7, fe80::/10),
so the client connects only to checked addresses, on the first request and
every redirect. No proxy, no Referer, a generic User-Agent, one shared
client. The download code moved to src-tauri/src/mdfetch.rs and is tested
against a local server: redirects to private addresses or another scheme,
redirect loops, non-image and SVG content types, the size cap without
Content-Length, and the time limit.

Consent lives in the backend now. "Show images" calls md_allow_remote,
which shows a native confirmation dialog and records the yes per document
until the app quits; md_remote_image refuses without it. md_local_image,
md_remote_image and open_external only accept documents the backend itself
opened or saved. mailto links may carry only to, cc, bcc, subject and body.
Local images are read with the size limit enforced while reading.

Large documents: big lists and tables are split between items and rows
(ordered lists continue with start, tables keep the header once and share
fixed column widths), changed chunks are swapped in one by one in short
slices, chunks out of sight use content-visibility, and the scroll map
reads chunk boxes instead of every block. The worker parses only the
newest request and is restarted when a parse runs longer than 5 seconds.
The Playwright check now covers a 1 MB list and a 1 MB table as well and
asserts the pause during the render after an edit.

Smaller fixes: links keep path and fragment apart (a "#" in a file name
works), UNC roots are kept, ":" is refused in .md link paths, a Windows
junction test, mXSS and chunk-boundary sanitiser tests, the argparse check
scans every script of markdown-it and its dependencies, the docs and the
security review describe the four commands and their guards.
Closing a tab now drops the backend's record of the document and the
user's yes for its remote images (md_forget); Save As forgets the old path.
A unit test covers the gate and a workspace test checks that closing a tab
tells the backend.

The docs and the security review now say what the "known document" check
is: a consistency check, since a script in the page could open a file
first. The native dialog is the boundary for the network, and after a yes a
script could use that document for any public https download until the tab
closes or the app quits. They also note that NAT64 and 6to4 addresses are
refused as a whole.

The download policy's test-only settings are no longer public fields, and
the Windows build job runs the core path checks (drive letters, UNC paths,
junctions) with cargo test -p nimble-core mdassets.
@Ferdinand99
Ferdinand99 merged commit 528da33 into main Nov 20, 2026
8 checks passed
@Ferdinand99
Ferdinand99 deleted the feat/markdown-view branch November 20, 2026 13:55
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