Skip to content

ipynb attachments: preserve image titles, resolve files/ output URLs#64

Merged
mmcky merged 2 commits into
mainfrom
feature/ipynb-attachment-fixes
Jun 12, 2026
Merged

ipynb attachments: preserve image titles, resolve files/ output URLs#64
mmcky merged 2 commits into
mainfrom
feature/ipynb-attachment-fixes

Conversation

@mmcky

@mmcky mmcky commented Jun 12, 2026

Copy link
Copy Markdown

Fixes #3
Fixes #4

Housekeeping batch for the ipynb attachment-embedding edge cases from PR #1's review trail (plus the async-read recommendation from #10, which is being closed alongside).

Changes

  1. Image attachment rewrite drops optional image title #4 — image titles preserved. embedImagesAsAttachments matched the optional "title" in ![alt](url "title") but dropped it on rewrite; the title group is now captured and re-emitted: ![alt](attachment:name "title"). (Note: titles can still be dropped earlier in the pipeline at parse time — that's outside this serializer fix's scope and Image attachment rewrite drops optional image title #4's report.)
  2. Image attachment embedding: resolve files/ output folder URLs #3files/ output-folder resolution. collectImageData resolved URLs only against the source file's folder, but finalizeMdast rewrites generated images (e.g. executed notebook outputs) to files/... paths that exist only under the export output folder — those were silently skipped. Resolution now falls back to the output folder.
  3. Review of PR #1: CommonMark ipynb export + image attachment embedding #10 item 3 — async reads. collectImageData uses fs.promises.readFile with Promise.all instead of synchronous reads (and drops the existsSync TOCTOU check in favor of try/read).

Verification

  • New unit test for title preservation (myst-to-ipynb: 58 tests green)
  • Manual end-to-end: built two projects with the local CLI — a static image (embedded, as before) and an image existing only under out/files/ (previously attachments: [], now embedded as attachment:dot.png)
  • Full monorepo build + test pass

🤖 Generated with Claude Code

Three small fixes to the attachment-embedding pipeline from PR #1's
review trail:

- embedImagesAsAttachments now captures the optional "title" group and
  re-emits it on the attachment reference (#4)
- collectImageData resolves URLs against the export output folder when
  source-relative resolution fails, so images finalizeMdast writes to
  files/ (e.g. executed outputs) are embedded instead of skipped (#3)
- image reads are async (fs.promises + Promise.all), per the
  recommendation recorded in #10

Fixes #3
Fixes #4

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens MyST→IPYNB image attachment embedding to handle a few edge cases encountered during notebook export, improving fidelity (titles) and correctness (resolving files/ output assets) while also making image reads non-blocking.

Changes:

  • Preserve optional Markdown image titles when rewriting image links to attachment: references.
  • Resolve attachment image paths against both the source folder and the export output folder (to catch files/... assets generated during export).
  • Switch image file reads to async (fs.promises.readFile) with concurrent processing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/myst-to-ipynb/tests/attachments.spec.ts Adds a unit test ensuring image titles are preserved during attachment rewrite.
packages/myst-to-ipynb/src/attachments.ts Captures and re-emits the optional "title" portion in rewritten attachment: image references.
packages/myst-cli/src/build/ipynb/index.ts Makes image collection async and adds output-folder fallback resolution for files/... URLs.
.changeset/ipynb-attachment-fixes.md Adds a patch changeset documenting the fixes for both myst-cli and myst-to-ipynb.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/myst-cli/src/build/ipynb/index.ts Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mmcky mmcky merged commit a34ab19 into main Jun 12, 2026
6 checks passed
@mmcky mmcky deleted the feature/ipynb-attachment-fixes branch June 12, 2026 05:00
mmcky added a commit that referenced this pull request Jun 12, 2026
Records squash a34ab19 as merged feature 13 (untagged) and appends it
to the myst-to-ipynb upstream candidate's commits — it fixes edge
cases in that feature's own code, so it ships in the same cherry-pick.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

Image attachment rewrite drops optional image title Image attachment embedding: resolve files/ output folder URLs

2 participants