markdown-it-include
markdown-it-include copied to clipboard
Rewriting paths
Assuming you're in /opt/doc/file.md
and you include ./included/first.md
, but that file has an inline image referencing ./img/logo.gif
, the resulting Markdown would be looking for /opt/doc/img/logo.gif
, while the image is actually at /opt/doc/included/img/logo.gif
.
Would it be possible (via a config flag or similar) to get the plugin to scan included files and rewrite any paths discovered accordingly? Something like path.resolve(basePath, path.resolve(path.dirname(path.join(basePath, importPath))
should do the trick, assuming basePath
is the path of the parent file and importPath
is the path of the imported file.
Sorry for my very late answer.
I'm not sure this issue is related to this plugin. The image paths are not computed by the includes.
When you write "inline image referencing ./img/logo.gif
", do you mean that in markdown 
?
I'm trying to use this in a Vuepress site, and I've only been able to get one combination of actual image location and path in Markdown to work. I've tried:
- adding the image to the include directory and referencing it (
./img/image.png
) - adding the image to the img directory of the vuepress root and calling it with a complete line (
/docs/img/image.png
) - adding the img to an img folder relative to the file calling the include, and referencing it as if the include was in the same path (
../img/image.png
).
Only the third option has worked for me so far. Unfortunately this model is antithetical to the idea of the include, because I'll need to make sure that image is available (even if only by symlink) in a corresponding ../img
folder wherever I use the include file.
I believe I'm having a similar issue - I'm trying to include a markdown file inside an included markdown file.
An example below:
# /docs/main.md
!!!include(./docs/include1.md)!!!
# /docs/include1.md
!!!include(./docs/include2.md)!!!
# /docs/include2.md
Content
Unfortunately, when including include2.md, it tries to load it from both main.md and include1.md, so that it tries to load /docs/include2.md and /docs/docs/include.md.
I am experiencing the same problem as @emiyl . Has anyone found a solution to including files that include other files?