npm / marky-markdown

npm's markdown parser
https://www.npmjs.com/package/@npmcorp/marky-markdown
405 stars 71 forks source link

Relative links in markdown README not being rewritten on npmjs.org #432

Closed shadowspawn closed 6 years ago

shadowspawn commented 6 years ago

Short version: relative links to other files from my package README are not being turned into github absolute references, and so do not work on npmjs.org.

What I Did

In my raw README I have relative links like:

See [Proxy Server](docs/proxy-server.md) for variables and advice for using a proxy server.

What I Expected

I assumed it would Just Work on both GitHub and npm, without thinking about the complications for npm hosting! (The other markdown file is not included in the published npm package.)

What Happened Instead

On npmjs the link does not work. The README page source has the relative link and has not been rewritten, and the page is not found:

<p>See <a href="docs/proxy-server.md" rel="nofollow">Proxy Server</a> for variables and advice for using a proxy server.</p>

On GitHub the README page source has:

<p>See <a href="/JohnRGee/nvh/blob/master/docs/proxy-server.md">Proxy Server</a> for variables and advice for using a proxy server.</p>

Details

When I did some digging into the problem I found that marky-markdown has support for rewriting relative links and images using the github package.repository if that is available (#306). Sounds good! But this does not appear to be happening for me.

I checked that github-url-to-object used by marky-markdown could resolve the repository as specified in my package.json and it could.

I changed my package repository reference to https in case #368 had resurfaced, but it did not make a difference.

I found another person talking about various problems with linked images, and they have a sample package with lots of types of links. None of the relative images render on npmjs:

https://www.npmjs.com/package/@code-therapy/packages-with-readme-relative-images

(I posted a message on the npm community but didn't score any replies in a couple of weeks.)

shadowspawn commented 6 years ago

I saw links working in yargs using a technically still relative link starting with a slash, which I had not considered.

I changed docs/foo to /docs/foo. Thought it was working but nope, still not working for my project.

shadowspawn commented 6 years ago

Filling in some details of setups.

Working link on npmjs for yargs:

Broken link on npmjs for me:

shadowspawn commented 6 years ago

There was a bug on npmjs end which has been addressed, hurrah! I'll update my npm community bug when I have seen it working.

cybairfly commented 1 year ago

I thought this was just a bug and cannot believe this is actually the standard behavior on npm. How can relative links work anywhere else but on npm where I publish the package? Is there any official solution? It's madness!!! ;-)