Skip to content

Zed extension: inline local images as data: URIs before export - #2

Merged
lecstor merged 4 commits into
mainfrom
clanker/92fc587c-zed-extension-inline-local-images-as-dat
Oct 2, 2026
Merged

lecstor merged 4 commits into
mainfrom
clanker/92fc587c-zed-extension-inline-local-images-as-dat

Conversation

@lecstor

@lecstor lecstor commented Oct 2, 2026

Copy link
Copy Markdown
Member

What

Ports the VS Code plugin's local-image inlining into the Zed sidecar. Export to PDF now rewrites ![alt](diagram.png) / <img src="diagram.png"> into data: URIs before posting, so images referenced by relative or absolute paths appear in the PDF; Validate accessibility still posts the Markdown verbatim. Unreadable files and files over the server's 5MB per-image cap are left as references and named in one non-fatal warning. README's "local images are not embedded" limitation is replaced with the new contract and the privacy line now says the bytes of referenced local images are sent with the export.

Phase-2 review fixes (commit 8cd7730)

  • Quadratic scanning removed. The ported VS Code regexes backtrack super-linearly on runs of unterminated references — measured ~3s for 64KB of ![ and ~13s for 160KB of ![a](, scaling quadratically, inside a single-threaded language server that otherwise cannot answer anything. Both scans and both replace passes are now left-to-right scanners with memoised delimiter lookups.
  • Failure order is document order across markdown and HTML refs, as the doc comment promised; previously all markdown failures preceded all HTML ones.
  • data-src no longer mistaken for src: \bsrc matched inside data-src="local.png", embedding the ignored attribute while the real src stayed a local path, so lazy-loaded images were still dropped.

Parity evidence: a differential fuzz against the previous regex implementation produced byte-identical output on 400/400 generated structured documents and 400/400 random structural-char documents.

Tests

  • npm test in server/ — typecheck, 47 unit tests, 5 stdio LSP integration tests: green.
  • New unit tests: document-order failures across syntaxes; data-src handling; a valid reference after a malformed one; three ~1–1.4MB pathological inputs scan in ~100ms total (pre-fix: ~13s at 160KB).
  • Integration test asserts the render body carries the data: URI while the validate body still carries diagram.png.

Port the VS Code plugin's inlineLocalImages into the sidecar: Export to
PDF now reads images referenced by local relative or absolute path and
embeds them as data: URIs, since the service cannot reach the user's
filesystem. Remote/data:/file: and protocol-relative URLs, unknown
extensions and code-block text are left alone; unreadable files and
files over the server's 5MB image limit are left as references and named
in one non-fatal warning. Validate accessibility does not inline.
The stdio LSP integration test now exports a document referencing a
local image and a missing one, asserting the render body carries the
data: URI while the validate body keeps the plain reference, and that
the missing image produces a non-fatal warning. README's v1 limitation
is replaced by the embedding behavior and the privacy line states that
referenced image bytes are sent with an export; CHANGELOG updated.
The VS Code regexes ported in 14d8046 backtrack quadratically on runs of
unterminated image references: measured ~3s for 64KB of `![` and ~13s for
160KB of `![a](`, in a single-threaded language server that blocks every
export and validate until the scan ends. Replace both scans and both
replace passes with left-to-right scanners that memoise the delimiter
lookups they would otherwise repeat, and fix two review findings:
- merge markdown and HTML failures into document order (the doc comment
  promised it; running the markdown pass first did not);
- require an attribute-name boundary for <img src=, so
  data-src="local.png" src=... no longer embeds the wrong attribute and
  leaves the real src local.

Differential evidence: 400/400 generated structured documents and 400/400
random structural-char documents produce byte-identical output to the
regex implementation, and 3x ~1-1.4MB pathological inputs scan in ~100ms.
@lecstor
lecstor merged commit 52f79b7 into main Oct 2, 2026
2 checks passed
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