Skip to content

Embed images #138

Closed
Closed

Description

@zzart

According to the docs

mkdocs.yml
docs/
    CNAME
    index.md
    subpage.md
    img/
        screenshot.png
index.md
![Screenshot](img/screenshot.png)

This is all good if you adding images to index.md

Now let's consider subpage:

subpage.md
![Screenshot](img/screenshot.png)

This image isn't found as server wants it to be in subpage/img/screenshot.png ??
So this forces invalid markup which doesn't work with other MD engines!

subpage.md
![Screenshot](../img/screenshot.png)

Activity

  1. dnrce commented on Sep 14, 2014

    @dnrce
    Contributor

    👍

  2. d0ugal commented on Oct 7, 2014

    @d0ugal
    Contributor

    The problem, is that subpage.md moves to subpage/index.html and thus the relative location of the img is incorrect. To fix this I think we need to infer an abolute location (by resolving the relative one to the .md file) and then use for image links.

    However, AFAICT, this will involve processing and re-writing the HTML which would get messy.

    Any better ideas?

  3. added this to the 0.10.0 milestone on Oct 7, 2014
  4. lovelydinosaur commented on Oct 7, 2014

    @lovelydinosaur
    Collaborator

    I'm confused. As far as I'm aware we do infer the correct relative location, which when translated into a URL will differ depending on if it was a link from subpage.md or index.md.

    To fix this I think we need to infer an abolute location

    I can't see why we'd need to be moving away from the current relative URLs, although if they're currently incorrectly generated for non-index pages then that needs fixing of course.

  5. d0ugal commented on Oct 7, 2014

    @d0ugal
    Contributor

    How should an image be added on subpage.md? Given the structure above? Maybe we just need to document this better, I don't fully understand but requiring people to put "../" seems wrong when that extra level isn't there in the source files.

  6. lovelydinosaur commented on Oct 7, 2014

    @lovelydinosaur
    Collaborator

    Yup indeed - the source should be marked up as ![Screenshot](img/screenshot.png) in both cases, but the translation to HTML should render different links in each case, including the required .. in one case but not in the other. As far as I was concerned we're handling both cases correctly when we translate them into relative URLs, but haven't checked lately.

  7. d0ugal commented on Oct 7, 2014

    @d0ugal
    Contributor

    Right, so I tested this and confirmed the issue. I'll investigate the fix. I'm not sure which bit of the code is responsible for this yet.

  8. added a commit that references this issue on Oct 8, 2014
    d9e5017
  9. modified the milestone: 0.10.0 on Oct 9, 2014
  10. gipi commented on Apr 27, 2021

    @gipi

    Sorry if I comment on this closed issue, but this situation with nested pages and images is not working with mkdocs 1.1.2 and I cannot find useful info in the documentation; in my case I have

    nav:
    - Home: index.md
    - Computer:
      - Hardware: hw.md
      - Embedded Systems:
        - General: embedded/index.md
        - Microcontrollers: embedded/micro.md

    where inside embedded/micro.md there is an image with path images/STM32-pinout.png but it's not rendered since the final path is not adapted to match the layout of the repo, indeed the mkdocs serve complains with

    WARNING - Documentation file 'embedded/micro.md' contains a link to 'embedded/images/STM32-pinout.png' which is not found in the documentation files..

  11. martinbira commented on Apr 27, 2021

    @martinbira

    @gipi Paths are not absolute. If your images folder is placed in your docs folder where the folder embedded is at the same level (docs, docs/images, and docs/embedded), the link should go to ../images/STM32-pinout.png.

  12. benutz commented on May 10, 2021

    @benutz

    I had the same problem where mkdocs just would not find the images in my media folder. The problem was my file endings. While I was linking to ./media/image.png in the markdown file the actual image had the file ending .PNG.

  13. waylan commented on May 10, 2021

    @waylan
    Contributor

    This issue was closed 6.5 years ago. The code which controls this has been rewritten multiple times since this issue was opened. Do not rely on the comments in this issue for current behavior. The current behavior is documented here. If you have any issues with the current documentation, then please open a new issue.

  14. locked as resolved and limited conversation to collaborators on May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions