Repository navigation
feat(editor): add Edit, Split and Read views for Markdown files - #51
Merged
Merged
Conversation
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.
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.
Summary
Markdown tabs (
.md,.markdown,.mdx, or any tab set to Markdown) get three views:A small Edit | Split | Read switch sits in the status bar for Markdown tabs only.
Ctrl/Cmd+Shift+Vtoggles Read andCtrl/Cmd+K Vtoggles 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
www.), heading anchors.HighlightStyle, so they follow the theme.src/styles/markdown.css, documented indocs/design-system.md).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 usecontent-visibility, and scroll sync reads chunk boxes, not every block. Renders wait for a pause in typing.Safety
<style>/style,<base>/<meta>/<link>,srcset,target,tabindex, etc.id/nameget auser-content-prefix;classkeeps only the renderer's own names;data-md-*from the file is dropped. The pane usescontain: layout paint.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, noReferer, a genericUser-Agent; image content types only; 16 MB with or withoutContent-Length; 20 s.open_external:http,https,mailto(onlyto,cc,bcc,subject,body; neverattach).open_external; relative.mdlinks open in a tab (path and fragment kept apart, UNC roots respected,:refused);#anchorsscroll; everything else is refused.CSP: unchanged. Images reach the page as
data:URLs (already allowed byimg-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.mdand the security review describe the four commands and their guards.Dependencies
markdown-it15.0.3 anddompurify3.4.17, pinned exactly, both released more than two weeks ago (transitive versions resolved with--before).open5.4.5 (withis-wsl,is-docker) to open links.reqwestandrustlsare used with the same features as the updater (rustls-no-provider+ ring), so no other new crates;urlandbase64were already in the tree.argparse(PSF-2.0), which markdown-it only imports in its command-line tool, is listed under the newnpmNotShippedinnotices-extra.jsonwith 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
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).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 withoutContent-Length, the time limit, names resolving to the local network, redirects to private names, literals, another scheme orfile:, redirect loops.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).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).