-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support for relative base_path in markdown_extensions #2154
Comments
I just first time tried |
Signed-off-by: Simon Christmann <simon@christmann.email>
Patched version of mkdocs: https://github.com/dersimn/mkdocs |
Hi, what's the status on this? |
I don't think there was any progress. But I didn't know about this issue and I opened this discussion some time ago: #2833 |
I actually very much like the idea of variables provided by MkDocs: markdown_extensions:
- pymdownx.snippets:
base_path: !ENV MKDOCS_CONFIG_DIR Depending on the order of things, env vars might be impossible to use. This might need a post-process step where |
I think I'd like to make it work like this: markdown_extensions:
- pymdownx.snippets:
base_path:
- !relative # Relative to current.md
- !docs_dir # Relative to docs_dir
- !config_dir # Relative to mkdocs.yml The issue is that indeed now we need some way to dig through the parsed YAML and find and replace the placeholders. There doesn't seem to be any standard way for that. Alternatively for a solution that's much much cleaner on MkDocs side but worse on the extension side, the value would actually be dynamically computed, but then we'd require each destination extension to call Otherwise of course places like this one get an error |
That gave me an idea- the value will respond not only to Linked a pull request accordingly. |
@oprypin does this allow things like |
No. |
Hm actually... I suppose |
Maybe this idea would be better: - !relative # Relative to current.md
- !relative $docs_dir # Relative to docs_dir
- !relative $docs_dir/some/child/dir
- !relative $config_dir # Relative to mkdocs.yml |
I find "relative" a bit confusing, but cannot find a better alternative. "path" would be too vague. "relpath" maybe too technical. In fact, relative-ness is not in question here since we use a variable ($docs_dir, $config_dir) which could return an absolute path for all we know. configpath? specialpath? dynamicpath? buildpath? docspath? mkdocspath? |
Any other ideas? ¯\_(ツ)_/¯ |
Nope, just go with what you prefer :) |
The other thing that's bugging me is this arbitrary |
mkdocs/mkdocs#2154 Signed-off-by: Simon Christmann <simon@christmann.email>
Doesn’t work currently (for whatever reason) mkdocs/mkdocs#2154
Many extensions need to know the base path of the currently rendered Markdown file, as they are supposed to include assets relative to the markdown file. Two of them are:
Both make use of the config variable
base_path
for including other files, so in order to configure it, you would specify:Currently
Please take a look at this example repository.
Currently you would have to include the
*.c
files with their full path, so in both files you would have to write:Why is this bad?
This is fine for Markdown files that are created and maintained for just one website, but we are currently including generic sub topics into our site that are shared among many repositories via
git submodule
. For e.g. some introduction topic on how to set up Docker. It's obvious that include paths must be relative to the Markdown file in this case, like:Desirable solution
If we want to be able to specify relative paths in every Markdown file, the
base_path
variable need to change with every Markdown file to be rendered, so it can't simply be included inmkdocs.yml
.This makes my feature request different from #998 #777 #761, because I'm not able to alter the
.md
files as they are shared over multiple projects.It would be nice if we could specify something like
that would then make MkDocs add the currently valid path as
base_path
variable for each rendered Markdown file.This is an issue for the one who calls the plugin, and not the plugin itself, as an additional (dynamic)
base_path
must be exchanged at this point in code:Currently (with the upper config from my example),
extension_configs
would contain something in the structure of this:We need to replace
$relative
here with the proper path depending on the current navigation.The text was updated successfully, but these errors were encountered: