question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

relative md links not working when in subdirectories

See original GitHub issue

If I have the following md directory structure:

/var/www/html/docs/ /var/www/html/docs/index.html /var/www/html/docs/test/ /var/www/html/docs/test/top.md /var/www/html/docs/test/subdir/ /var/www/html/docs/test/subdir/subdir.md

With index.html contains: <zero-md src="test/top.md"></zero-md>

And top.md contains: [subdir](subdir/subdir.md)

Then when browsing to “http://<domain.com>/docs/” the “subdir” link in the zero-md rendered html of top.md incorrectly points to: http://<domain.com>/docs/subdir/subdir.md

whereas the “subdir” link should point to: http://<domain.com>/docs/test/subdir/subdir.md so there is a missing path sub dir of “test”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zerodevxcommented, Aug 5, 2020

Better handling of relative links is definitely in the pipeline. This is especially true for the use case @fbalady-synamedia described:

Regarding why the link, although the issue is the same, the primary use case I’m after is linking to an image in an “images” subdirectory using notation. That also doesn’t work correctly when using relative links.

However, in the case of intercepting anchor links to another .md file (within the same domain), and doing a re-render, this falls within the realms of client-side routing and SPA, so I’m not sure if it’s something people would expect.

Instead, a gist (or a recipe) like what @neskk posted would work quite well outside the remit of zero-md - where you can optionally chain History API pushState to update the URL bar if your use-case requires it.

IMO, what zero-md needs is a more elegant (and more up-to-date) way that exposes hooks where consumers can subscribe to and extend functionality, customised to their needs, if required. This also goes to my Long List of Stuff to Change in the new release. 😅

1reaction
zerodevxcommented, Feb 22, 2020

Thanks for the feedback @fbalady-synamedia - since zero-md is due for an update I’ll probably add logic for relative link handling in the next release soon. Let’s keep this issue open for now - stay tuned!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub relative link in Markdown file - Stack Overflow
If i was linking from a .md in one subdir to another, i think it would handle relative link just fine. Problem occurs...
Read more >
relative links in markdown to the current directory or via subdir ...
The relative link is translated incorrectly to the root of the project instead of the current directory. Relative links to the current directory ......
Read more >
Configuration - MkDocs
An external link may be a full URL or a relative URL. Any path which is not found in the files is assumed...
Read more >
Relative urls in readme.md files only work half the time. (BB ...
I've confirmed that the problem with relative links only works if the readme is rendered at a specific commit. If it is rendered...
Read more >
Reference - mkdocs-literate-nav - GitHub Pages
Links in the nav file directly under the root docs dir are relative to the docs dir, and for nav files that are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found