Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative links in pages below the top-level document folder point to the wrong path #292

Closed
jdhoek opened this issue Dec 18, 2014 · 14 comments · Fixed by #293
Closed

Relative links in pages below the top-level document folder point to the wrong path #292

jdhoek opened this issue Dec 18, 2014 · 14 comments · Fixed by #293
Labels
Milestone

Comments

@jdhoek
Copy link

jdhoek commented Dec 18, 2014

Relative image links in pages below the top-level document folder seem to point to the wrong path.

Reproduction

I've created a minimal reproduction case:
https://github.com/jdhoek/mkdocs-test-relative-image-links

The reproduction case contains this file structure:

├── docs
│   ├── index.md
│   ├── subdir
│   │   ├── sub.md
│   │   └── sub.png
│   └── toplevel.png
└── mkdocs.yml

mkdocs serve and mkdocs build correctly process the Markdown files in the top-level folder docs_dir, but with the Markdown file in the sub-folder the relative image links are broken.

mkdocs-relative-image-links

@tomchristie
Copy link
Member

Probably same as #77 but this is more helpful.

@jdhoek
Copy link
Author

jdhoek commented Dec 18, 2014

I wasn't sure if #77 was the exact same issue. Thanks for referencing it.

@d0ugal
Copy link
Member

d0ugal commented Dec 18, 2014

This is a great report, thanks very much.

Things gets a bit confusing as, I think, we have links in three different scenarios.

  • Links to markdown (as far as I'm aware, no known issues)
  • Links to static assets like images (this issue)
  • Either of the above on a "static page" like the 404.html which could be returned under many paths. (this is probably relative url's can cause bad links #77).

The first two vary because we move the location of markdown files (my/document.md becomes my/document/index.html and is thus one level deeper). So, these issues are probably subtly different but I expect a fix will need to take all the above into account.

@jdhoek Just to check, did you test this against the latest release or via git master? There was some fairly recent fixes for images, but I can't remember if it made the last release or not :)

@d0ugal
Copy link
Member

d0ugal commented Dec 18, 2014

... I just confirmed, it is still an issue with the latest dev version.

@d0ugal
Copy link
Member

d0ugal commented Dec 18, 2014

I can't see an obvious reason, but the broken image path is coming out as ../../sub.png when it should be ../sub.png.

@d0ugal d0ugal added the Bug label Dec 18, 2014
@d0ugal d0ugal added this to the 0.12.0 milestone Dec 18, 2014
@d0ugal
Copy link
Member

d0ugal commented Dec 18, 2014

Gah, I see the issue with images. It comes down to my miss-understanding of the url rewriting when I added support for them. it is actually a coincidence that any of these work. 😳

Clearly the tests I added for this are completely bogus. I'll look into a real fix.

Using create_media_urls here is completely wrong. https://github.com/tomchristie/mkdocs/blob/aaf344630f4732ae58d1da28b25d0c02bd8d56b9/mkdocs/relative_path_ext.py#L59

@jdhoek
Copy link
Author

jdhoek commented Dec 18, 2014

@d0ugal
My apologies, I should have mentioned the version. I am using the latest stable release from PyPI; v0.11.1.

@Mopster
Copy link

Mopster commented Apr 2, 2015

I came across this problem today, any eta on v0.12 ? :-) Currently I have to choose between working images in the GitHub repo or on the generated site :-)

Mopster pushed a commit to axsh/wakame-vdc that referenced this issue Apr 2, 2015
@d0ugal
Copy link
Member

d0ugal commented Apr 2, 2015

@Mopster The 0.12.0 milestone is here. I've got it down to just a smallish number of bugs. https://github.com/mkdocs/mkdocs/milestones/0.12.0 - I am hoping to do it this weekend, but no guarantees ;)

@Mopster
Copy link

Mopster commented Apr 2, 2015

great! gonna show it off to the office today ;-)

@Atlas-Night-Out
Copy link

I also have these issues been trying loads of different ways to get images to show up on GitHub, with no luck. They work on a website domain and also in MKdocs server too just no luck at all in Github. Can anyone help me with this or is it not possible?

@lambdamusic
Copy link

I was able to get this working by using a relative path. Eg in sub.md:

![Screenshot](../../img/image.jpg)

Obviously not ideal cause each time one needs to remember the file location relative to the img folder.. but it works.

@alex20465
Copy link

alex20465 commented Apr 28, 2022

I have the same issue, the solution is clear... just change the path.

BUT ! the relative paths markdown -> assets (./xy) is rendered correctly by almost every platform (github, gitea, vscode etc.)

once you copy a document structure to mkdocs, we have to change all paths basically to correct into "wrong" to the other platforms.

this quite sucks since the assets relative path is current to the markdown BUT incorrect after build.

mkdocs needs a assets-uri-resolver strategy configuration.

@kuchaguangjie
Copy link

Does this answer on SO fix your problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants