mkdocs-include-markdown-plugin icon indicating copy to clipboard operation
mkdocs-include-markdown-plugin copied to clipboard

pymdownx.tabbed breaks relative-url-rewrite for nested imports

Open 9Lukas5 opened this issue 2 years ago • 4 comments

I have the following example structure:

docs
├── a
│   ├── assets
│   │   └── screenshot.png   
│   ├── page-a.md                       # imports _part-site.md
│   ├── _part-site.md                   # imports _screenshot.md
│   └── _screenshot.md              # has image with relative path to assets/screenshots.png
├── b
│   └── page-b.md                       # imports ../a/part-site.md
└── index.md

While the on page-a the image is shown fine, on page-b it is not found, as the relative image url wasn't rewritten correctly.

This behaviour is only the case, when in _part-site.md the _screenshot.md is included into a pymdownx.tabbed tab.

Attached is a minimal example for this scenario

9Lukas5 avatar Sep 30 '23 00:09 9Lukas5

This is the expected behaviour as the _part-site.md file includes _screenshot.md which is just a replacement for:


This is the screenshot site from `docs/a`

![Some title](./assets/screenshot.png)

The link is just handled by Mkdocs as if the file were in the same relative folder. I think that you need to use an absolute path. What behaviour you would expect here?

mondeja avatar Oct 12 '23 18:10 mondeja

Outside of the tabbed environment the plugin successfully rewrites the relative path accordingly, so the image shows in the a and b subpaths :eyes:

9Lukas5 avatar Oct 12 '23 18:10 9Lukas5

I'm not experiencing the same behaviour as you with the example that you've shared. The path is not rewritten correctly when is not included into a pymdownx.tabbed tab.

mondeja avatar Oct 14 '23 20:10 mondeja

With the example originally shared you don't, yes, because that was designed to show-off what was an obvious bug to me. I didn't include it to show that it is working under b/ if the import of _screenshot.md in a/_part-side.md was done outside the tabbed environment.

But that can be changed, see below:

As for your this:

This is the expected behaviour as the _part-site.md file includes _screenshot.md which is just a replacement for...

The readme states:

rewrite-relative-urls (true): When this option is enabled (default), Markdown links and images in the content that are specified by a relative URL are rewritten to work correctly in their new location. Possible values are true and false.

So, with the updated example you can see, with the include chain page-b.md -> _part-site.md -> _screenshot.md the image relative url rewrite works for the _screenshot.md include that is not indented, but is broken for indented lines.

Oh and as I'm writing this, I discovered it's not limited to the tabbed environment, it's also broken if indented into a list (see example code)

So I'm sorry, but according to the readme and the fact that it's working without additional environments (like lists, tabbed,...) around it, I'm still thinking of this as a bug or at least a mentionable technical limit, but not expected behaviour.

9Lukas5 avatar Oct 15 '23 07:10 9Lukas5