Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 7

Link to a section in another README.md file

Hey all,

 

I'm trying to link to another section in a different README.md in a different directory of my project and I'm not having much success with it. I've tried:

 

`[linky](src/README.md#section)`

 

and it links to the README.md file, but not to the section within the file.

 

Does anyone know if this can be done?

 

Any help would be greatly appreciated!

6 Replies
Commander Lvl 3
Message 2 of 7

Re: Link to a section in another README.md file

Most of the times when you hover with your cursor over the title you see a link symbol appearing next to it. Try clicking that. It then copies the link to your clipboard. If you use that link it should work.

 

If that doesn't work either it may be your browser who is playing games with you.


- Mark
Community Manager
Message 3 of 7

Re: Link to a section in another README.md file

Seems to work for me in this test repo I have. You have the link target has to match the "dasherized" version of the heading. Did you do that?

 

Let us know if you have any other questions.

Copilot Lvl 2
Message 4 of 7

Re: Link to a section in another README.md file

Hi lee-dohm,

I'm having the same issue as the original poster. It seems to me that your solution is leveraging full http path, whereas what the original author and I are trying to do is leverage the markdown linking.

So assume you have two files F1.md and F2.md in the same folder.

Assume further that F2.md has a section called Introduction, and you'd like to link to Introduction in F1.md.

If I write in F1.md the following: "As described in [Introduction](F2.md#Introduction)..." then Ctrl+clicking on this link opens F2.md, but it does not focus on the section Introduction.

 

Any idea how to make that work?

Community Manager
Message 5 of 7

Re: Link to a section in another README.md file

If you look at the source for the Markdown file I linked to, you'll notice that I didn't give the full HTTP path. I only gave just enough to fully specify the file that I wanted (since it is in another directory) and the section within the file:

 

[link](other-directory/README.md#section)

Can you show me an example in a public repository that isn't working as expected?

Copilot Lvl 2
Message 6 of 7

Re: Link to a section in another README.md file

Thanks, lee-dohm, for your courteous reply. I had looked at the link in your comment above and assumed that was the link you were talking about. I suppose Github simply turned your relative link into a full url link.

As to your question, the problem I'm facing is occurring inside a markdown editor called Typora. I was not sure if this was a bug attributable to the editor or if it was a limitation in the markdown specs. Based on your code, this must be a bug of the editor itself.

 

Egan.

Highlighted
Community Manager
Message 7 of 7

Re: Link to a section in another README.md file

If you're asking about functionality that isn't on GitHub, then it wouldn't necessarily work the same way. Some of this link-handling behavior is specific to GitHub.

 

You should be able to use relative links though. So if you're trying to link to another document in the same folder, then you should be able to use:

 

[link to section](./F2.md#section)

I hope that helps!