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
Ability to refer to links within included files from different levels of docs #2404
Comments
I suspect there is no way to make this work at this time. When MkDocs encounters relative URLS to local files it properly modifies them (so long as the path points to a file which exists). In all other situations, MkDocs makes no changes to the URL. Therefore you are completely responsible for ensuring the URL is accurate. The problem with relative URLs in your case is that MkDocs has no knowledge of There is one other potential solution which occurs to me. If the dev server incorporated the subdirectory, then absolute URLs would work consistently on both the hosted site and in the dev server. For example, if the site_url was set to |
Yes, that would be good to have, regardless of any other considerations. What would be even better is to just support absolute URLs :s |
So yes, I really like @waylan's idea. I have implemented it at oprypin@b2ac728, but that depends on PR #2385 (and I would prefer not to add this incompatible change directly to that PR). |
I like it 👍. Not sure why you feel the need to keep it separate though. I see it as a "feature" of the new server implementation. And as |
mkdocs-include-markdown-plugin rewrites relative URLs including markdown snippets, I suggest you to use it. Otherwise, seems that the problem of rewriting links as absolute ones has been solved, at least as far as possible. I think that relative rewriting of included URLs is the plugins job, so should this issue be closed? |
The paths in the include are relative to the file where it is included. We could fix this to correct the relative path. But, because we've reorganised the file structure, we have different Markdown files at different levels in the directory hierarchy now including this same include file. Therefore, there is no single relative path that will fix the link in all places that the file is included: we might be including this file from Markdown source files that are either two or three levels deep in the directory hierarchy. As far as I can tell, there is no direct solution for this, and the simplest fix is to use an absolute URL that is not part of the docs at all: mkdocs/mkdocs#2404
The paths in the include are relative to the file where it is included. We could fix this to correct the relative path. But, because we've reorganised the file structure, we have different Markdown files at different levels in the directory hierarchy now including this same include file. Therefore, there is no single relative path that will fix the link in all places that the file is included: we might be including this file from Markdown source files that are either two or three levels deep in the directory hierarchy. As far as I can tell, there is no direct solution for this, and the simplest fix is to use an absolute URL that is not part of the docs at all: mkdocs/mkdocs#2404
The paths in the include are relative to the file where it is included. We could fix this to correct the relative path. But, because we've reorganised the file structure, we have different Markdown files at different levels in the directory hierarchy now including this same include file. Therefore, there is no single relative path that will fix the link in all places that the file is included: we might be including this file from Markdown source files that are either two or three levels deep in the directory hierarchy. As far as I can tell, there is no direct solution for this, and the simplest fix is to use an absolute URL that is not part of the docs at all: mkdocs/mkdocs#2404
The paths in the include are relative to the file where it is included. We could fix this to correct the relative path. But, because we've reorganised the file structure, we have different Markdown files at different levels in the directory hierarchy now including this same include file. Therefore, there is no single relative path that will fix the link in all places that the file is included: we might be including this file from Markdown source files that are either two or three levels deep in the directory hierarchy. As far as I can tell, there is no direct solution for this, and the simplest fix is to use an absolute URL that is not part of the docs at all: mkdocs/mkdocs#2404
As mentioned above, the mkdocs-include-markdown-plugin seems to support this by rewriting relative URLs. Also, upcoming MkDocs v1.6 brings support for absolute URLs, which would solve this too. Therefore we'll close this as completed 🙂 Feel free to comment further. |
I have two docs (doc-a and doc-b) that pull the same smaller doc (doc-s) using the markdown include extension.
Doc-s has a link that refers to another internal doc. When doc-s gets included in doc-a and doc-b, the internal link doesn't work since the no. of levels that needs to be specified for the relative paths are different (
(../../../<internal doc path>)
for doc-a and (../../../../<internal doc path>
) for doc-b).We tried using the absolute URL instead. Though it works fine locally (mkdocs serve), it doesn't work in the hosted version, since the root folder has child folders (in the example below, en and latest get elimintated).
Example:
docs.example.com/en/latest
Is there a way to retain the link in the smaller doc (doc-s) relative to the site root (docs.example.com/en/latest)?
The current mkdocs.yml config -
The text was updated successfully, but these errors were encountered: