Preview

community mirrored

Read an upstream page before copying it: rendered, read-only, nothing written to the vault.

Open

  • In the check view, a Markdown file’s name, in What’s new or All files, previews it at the head the check saw. Only rows that can be mirrored or forked have one. So does the name of a file changed (not gone) in Mirrors changed upstream or Forks changed upstream.
  • Preview a file from a source: pick source (skipped if one), fetch head, pick file, as Mirror a file from a source does.

One Preview tab, in the main area, is reused. Its state (Preview: source, path, blob, branch, commit, tree) is saved with the workspace, so it comes back after a restart.

Cost

Clones are partial (--filter=blob:none): a preview fetches that one page’s blob, a round trip the size of the page, or nothing when the clone has it. Finding the blob is a local ls-tree. Mirroring or forking it afterwards reads it from the clone. Attachments aren’t fetched: embeds that aren’t in the vault don’t show, and web images are links (Safety).

View

Header: remote name · branch · path, and whether it is mirrored already (“Mirrored at …”, “, this version” when it is) or forked (“Forked n times”, “, the latest from this version”), from the metadata cache. Then:

  • Mirror, when it isn’t mirrored: as Mirror in the check view (mirror.md), at the preview’s head.
  • Update, when it is mirrored at another version: as Update in the check view, to this version.
  • Fork: the fork modal (fork.md). A mirrored file’s mirror moves, as in the check view.
  • Compare, when the latest fork isn’t settled for this version: the compare (compare.md) of this version with it. As everywhere: the copy where it is open, or in this pane, and the Upstream view, showing this same version, in a group to its right.
  • Compare mirror, when it is mirrored at another version: the same, with the mirror; then the fork’s is Compare fork.

None of them asks about content that runs (copy-safety.md): the alert was on screen.

  • Rendered / Source, above the text: the text as it is, front matter included, or rendered, made safe first (Safety). The Upstream view adds Changes (compare.md).

Rendered, front matter is left out and links resolve from the path its mirror has or would have, so links to mirrored pages work. The tab closes once Mirror or Update has run (its notice says how it went) or a fork is written; cancelling the fork modal leaves it open.

Safety

A page is rendered before anyone chose to trust it, so its text is defused first (defused()): no plugin runs code from it, and nothing loads from the web. The Upstream view does the same. Each rewrite puts a zero-width space where it breaks the form, which leaves what is seen unchanged, in code too. So the whole text is rewritten, without telling code from prose: a wrong guess there can’t leave anything live.

  • Code blocks: the language after every run of three backticks or tildes is broken (```·dataviewjs), wherever it is: no parsing, so fences behind any mix of quote and list markers are caught. No plugin’s code block processor takes them. Highlighting goes with it. Not wrapped in markers: that needs knowing where each block ends, and a wrong guess turns code into live Markdown.
  • Inline queries: code starting = or $= (Dataview’s defaults) isn’t evaluated.
  • Images on the web, ![](https://…) or //…, and every reference image ![a][id], become links. Local images and ![[…]] embeds show.
  • HTML: a tag stays only if it is plain formatting (br, sup, span, details, …) and its attributes fetch nothing (//, url(, @import, src=, …), name no language- class and set no on… handler. A link’s own href is allowed. Anything else, and comments, show as text. Autolinks stay.

Alerts. What a page holds that runs or loads once it is a note is told in a box under the header (defuse() finds it as it defuses, from the start of the text, front matter included; once per load). Only the first 5,000,000 characters (SCAN_LIMIT) are looked through: a scan takes about 16 ms a million characters, and git allows a page of 64 MB. Longer, the alert says the rest wasn’t checked, and there is one even when nothing was found: This page was not checked to the end. The copy to render is made the first time it is rendered: a page only seen as source isn’t rewritten. A sentence each:

  • Code blocks a plugin runs: dataviewjs, datacorejs/jsx/ts/tsx, js-engine, meta-bind-js-view, run-* (Execute Code), counted by language. Not js or dataview: shown or queried, not run as code, and on every technical page.
  • Inline JavaScript, `$= …`. Not `= …`: a query.
  • Templater commands, <% %>: shown as text here, but Templater can run them when a note is made from the page.
  • HTML that runs, embeds or submits (script, iframe, form, style, …) and event handlers.
  • Images and HTML that would load from the web. A reference image counts when its definition is to the web.

Then: here none of it runs or loads, rendered or not; mirrored or forked, it is an ordinary note, where it can. With an alert, the view opens on the source, so what is there is seen as it is; Rendered renders it defused. Without, it opens rendered.

Source view shows the text as is: it is never parsed. Over 500,000 characters (RENDER_LIMIT), nothing is rendered: the source shows, cut there, and the header says so. The blob is still fetched whole: its size isn’t known before.

Code

Pure: src/preview/preview.ts, src/copy/safe.ts (shared with copying). Vault: src/preview/run.ts. UI: src/ui/preview-view.ts on src/ui/file-view.ts (shared with the Upstream view), the row link in src/ui/file-rows.ts. Command: src/fork/command.ts.