我正在编写一个大型Markdown文档,并希望在开始时放置一个目录,将提供到文档中各个位置的链接。我该怎么做呢?

我试着用:

[a link](# MyTitle)

其中MyTitle是文档中的一个标题,但这不起作用。


当前回答

因为在评论中提到了MultiMarkdown作为一个选项。

在MultiMarkdown中,内部链接的语法很简单。

对于文档中的任何标题,只需以这种格式给出标题名称[heading][]以创建内部链接。

阅读更多:MultiMarkdown-5交叉引用。

Cross-References An oft-requested feature was the ability to have Markdown automatically handle within-document links as easily as it handled external links. To this aim, I added the ability to interpret [Some Text][] as a cross-link, if a header named “Some Text” exists. As an example, [Metadata][] will take you to # Metadata (or any of ## Metadata, ### Metadata, #### Metadata, ##### Metadata, ###### Metadata). Alternatively, you can include an optional label of your choosing to help disambiguate cases where multiple headers have the same title: ### Overview [MultiMarkdownOverview] ## This allows you to use [MultiMarkdownOverview] to refer to this section specifically, and not another section named Overview. This works with atx- or settext-style headers. If you have already defined an anchor using the same id that is used by a header, then the defined anchor takes precedence. In addition to headers within the document, you can provide labels for images and tables which can then be used for cross-references as well.

其他回答

这可能是过时的线程,但创建内部文档链接markdown在Github使用… (注意:小写#title)

# Contents
 - [Specification](#specification) 
 - [Dependencies Title](#dependencies-title) 

## Specification
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. 

## Dependencies Title
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. Example text blah. Example text blah. 
Example text blah. Example text blah. 

这是一个很好的问题,所以我修改了我的答案;

可以使用- #,##,###,####创建到任何大小的标题的内部链接 我在下面创建了一个简单的例子… https://github.com/aogilvie/markdownLinkTest

使用kramdown,看起来效果不错:

[I want this to link to foo](#foo)
....
....
{: id="foo"}
### Foo are you?

我看到有人提到过

[foo][#foo]
....
#Foo

工作效率很高,但对于除标题外的元素或具有多个单词的其他标题,前者可能是一个很好的选择。

因为在评论中提到了MultiMarkdown作为一个选项。

在MultiMarkdown中,内部链接的语法很简单。

对于文档中的任何标题,只需以这种格式给出标题名称[heading][]以创建内部链接。

阅读更多:MultiMarkdown-5交叉引用。

Cross-References An oft-requested feature was the ability to have Markdown automatically handle within-document links as easily as it handled external links. To this aim, I added the ability to interpret [Some Text][] as a cross-link, if a header named “Some Text” exists. As an example, [Metadata][] will take you to # Metadata (or any of ## Metadata, ### Metadata, #### Metadata, ##### Metadata, ###### Metadata). Alternatively, you can include an optional label of your choosing to help disambiguate cases where multiple headers have the same title: ### Overview [MultiMarkdownOverview] ## This allows you to use [MultiMarkdownOverview] to refer to this section specifically, and not another section named Overview. This works with atx- or settext-style headers. If you have already defined an anchor using the same id that is used by a header, then the defined anchor takes precedence. In addition to headers within the document, you can provide labels for images and tables which can then be used for cross-references as well.

在Markdown规范中没有这样的指令,抱歉。

除了以上的答案,

当在YAML头中设置选项number_sections: true时:

number_sections: TRUE

RMarkdown会自动为你的章节编号。

要引用这些自动编号的部分,只需在您的R Markdown文件中放入以下内容:

(我的部分)

Where My Section是Section的名称

这似乎不管section级别都有效:

#我的部分

##我的部分

###我的部分