49

I have two markdown files: a parent.md and a child.md.

So parent.md:

# Main section

## sub-section

I'd like to make reference to ## sub-section from child.md.

Any ideas?

Jordi
  • 20,868
  • 39
  • 149
  • 333

3 Answers3

67

In MarkDown, reference is possible using hyperlink :

#  Main section

##  [sub-section](./child.md#sub-section)    
##  [sub-section](/child.md#sub-section)
##  [sub-section](child.md#sub-section)

Unfortunately the direct embedding of another Markdown file is not possible

Alternatives

An alternative is the use of an incision from a capture of the other file:

#  Main section

##  sub-section

![ImageTheOtherMarkdown](Screent.png)
Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
  • 6
    If you have a section that has uppercase words, change them to lowercase for the link. Spaces also become dashes. For example, if the section was called Sub Section1, it would be [sub-section1](./child.md#sub-section1) – nedstark179 Dec 15 '21 at 13:28
19

What worked for me is in parent.md:

[link](./file.md#section-name) // note the dash!

In child.md:

## ...
## section name

I tested this on my local via JetBrains IDE.

ivqonsanada
  • 103
  • 2
  • 6
maraps
  • 191
  • 1
  • 2
  • 1
    This works in VSCode and in mkdocs. As [maraps](https://stackoverflow.com/users/15201180/maraps) pointed out, the section names in the target are slugified with dashes. – dr_cornelius Mar 16 '23 at 11:50
0

The snippets macro gets quite close to that function I've asked to add support to importing particular lines from files on manually setting anchors on one files and then injecting the anchor section in another file

Mike
  • 1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34633126) – sanitizedUser Jul 08 '23 at 06:47