mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

Emebed directive fails to resolve images from file path

Open JimMadge opened this issue 4 weeks ago • 1 comments

Description

When using the embed directive to reuse an image or figure, if the images path is a local path (e.g. ../figures/img1.png), the image will not appear. It seems that the imported MyST keeps the file path, so your MyST project is looking for a file in your project, which does not exist because it is part of the external project.

If, instead, the image path is a URL (e.g. https://...) the image will appear (presumably because that URL is correct globally).

Minimal working example

# myst.yml
# See docs at: https://mystmd.org/guide/frontmatter
version: 1
project:
  id: b1a172b6-4707-456c-a8f8-f8c6217f3689
  # title:
  # description:
  # keywords: []
  # authors: []
  # github:
  # To autogenerate a Table of Contents, run "myst init --write-toc"
  references:
    myst-guide: https://mystmd.org/guide
    ttw: https://book.the-turing-way.org
site:
  template: book-theme
  # options:
  #   favicon: favicon.ico
  #   logo: site_logo.png
# index.md
# Index

This works
:::{embed} xref:myst-guide#subfigure
:::

This doesn't work
:::{embed} xref:ttw#linting-no
:::

Error message

⛔️ index.md Cannot find image "../../../figures/linting-no.jpeg" in /Users/jmadge/Documents/embed_figure_bug

The path here is the relative path of the figure on the external project.

Proposed solution

If I understand what the problem is, the imported image paths need to be resolved to the URL where the external project is hosted, rather than copying the path from that projects source.

I've spoken with @agoose77, seems there is a more general problem where children of imported nodes not processed and treated like they belong to your project.

Additional notes

JimMadge avatar Oct 30 '25 13:10 JimMadge