Skip to content

Inconsistency in how image paths are handled between markdown links and img hrefs #6403

@dwmkerr

Description

@dwmkerr

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

(I'd be happy to work on this issue if someone can point me in the right direction to get started)

It could be argued this is not a bug, but it is certainly unintuitive behaviour that makes things a little harder to work with.

Consider a folder in docs that contains a markdown file and an image (this is a pattern that I think could be pretty comon - each docs page contains its own folder of images, i.e. co-locating images with their associated document, if they are specific to the document, rather than shared across the site):

docs
-> folder1
-> folder1/index.md
-> folder1/images/image.png

The following markdown snippet will correctly render the image:

![Alt Text](./images/image.png)

As this works. GitHub also correctly renders this in pull requests etc.

I think the user would expect that the following would also work:

<img alt="Alt Text" src="./images/image.png" width="480px" />

This form might be used if you want to control the style/width of an image. The snippet above also renders correctly in a GitHub markdown preview in a code change.

However, instead we have to use this form:

<img alt="Alt Text" src={require('./images/image.png').default} width="480px" />

This works - however it is unintuitive that this form has to be used given that the pure markdown version works with relative paths properly. It also means that typical markdown previewing tools (such as GitHub's own markdown renderer) fail to render the images. This just makes the process of working with images that are co-located with documents a bit more painful.

I love the tool - I'm migrating Effective Shell to Docusaurus at the moment - one of the reasons I prefer it to Hugo is that I don't have to use weird platform specific features (like relref in Hugo) - I can just use plain old markdown links. But this img behaviour is a little odd. I understand it's a low priority issue with a simple workaround, but feels like the entire tool would be a little more user friendly (especially for complex folder structures like mine) if it was possible to use plain old relative paths in img tags.

An example of this inconsistency (which also shows how GitHub fails to render the img tags properly) is at: https://github.com/dwmkerr/effective-shell/blob/main/effective-shell/docs/01-transitioning-to-the-shell/01-getting-started/index.md

Please see the sandbox at: https://codesandbox.io/s/serene-butterfly-fz6tk?file=/docs/image-issue/image-issue.md

Steps to reproduce

Please see above, or the code at:

Expected behavior

Image tags would be able to reference images using relative paths without any special treatment.

Actual behavior

Image tags that reference images in relative paths require us to use require - this fails to preview in many common markdown renderers - such as GitHub's own renderer, meaning we are more likely to make mistakes when using these paths.

Your environment

Reproducible demo

https://github.com/dwmkerr/effective-shell/tree/main/effective-shell

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionclosed: working as intendedThis issue is intended behavior, there's no need to take any action.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions