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

我试着用:

[a link](# MyTitle)

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


当前回答

是的,markdown确实做到了这一点,但你需要指定名称anchor <a name='xyx'>。

一个完整的例子,

这就创建了链接 (任务)(#任务)

在文档的其他地方,您创建了命名锚(不管它叫什么)。

<a name="tasks">
   my tasks
</a>

注意,你也可以把它环绕在标题上。

<a name="tasks">
### Agile tasks (created by developer)
</a>

其他回答

关于<a name="">技巧的更多旋转:

<a id="a-link"></a> Title
------

#### <a id="a-link"></a> Title (when you wanna control the h{N} with #'s)

这可能是过时的线程,但创建内部文档链接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

一些额外的事情要记住,如果你曾经在你想导航到的标题中的符号…

# What this is about


------


#### Table of Contents


- [About](#what-this-is-about)

- [&#9889; Sunopsis](#9889-tldr)

- [:gear: Grinders](#it-grinds-my-gears)

- [Attribution]


------


## &#9889; TLDR


Words for those short on time or attention.


___


## It Grinds my :gear:s


Here _`:gear:`_ is not something like &#9881; or &#9965;


___


## &#9956; Attribution


Probably to much time at a keyboard



[Attribution]: #9956-attribution

... 标题字符串中的#、;、&和:之类的内容通常会被忽略/加条纹而不是转义,还可以使用引用样式的链接来简化快速使用。

笔记 GitHub在提交、自述文件等中支持:word:语法,如果对使用'em感兴趣,请参阅gist(来自rxaviers)。 现代浏览器几乎可以在其他任何地方使用十进制或十六进制;来自w3schools的备考单非常方便,特别是如果使用CSS::before或::after带符号的伪元素更符合你的风格。

加分吗?

以防有人想知道标题中的图像和其他链接是如何解析为id的……

- [Imaged](#alt-textbadge__examplehttpsexamplecom-to-somewhere)


## [![Alt Text][badge__example]](https://example.com) To Somewhere


[badge__example]:
  https://img.shields.io/badge/Left-Right-success.svg?labelColor=brown&logo=stackexchange
  "Eeak a mouse!"

警告

MarkDown渲染因地而异,所以像……

## methodName([options]) => <code>Promise</code>

... 在GitHub上将有一个带有id的元素,例如…

id="methodnameoptions--promise"

... vanilla sanitation会导致id为…

id="methodnameoptions-codepromisecode"

... 这意味着从模板中编写或编译MarkDown文件要么需要针对一种slugifeing方式,要么为各种巧妙的方式添加配置和脚本逻辑,比如清理标题的文本。

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

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

我看到有人提到过

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

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

Gitlab 使用 GitLab Flavored Markdown (GFM)

这里“所有markdown -render头自动获得id”

可以使用鼠标:

将鼠标移到页眉上 将鼠标移动到悬停选择器上,从头部左侧可见 复制和保存链接使用鼠标右键单击 例如在README中。md文件我有头文件:

Boettcher函数的级数展开公式

它给出了一个链接:

https://gitlab.com/adammajewski/parameter_external_angle/blob/master/README.md#series-expansion-formula-of-the-boettcher-function

前缀可以删除,所以这里的链接是简单的

file#header

这里的意思是:

README.md#series-expansion-formula-of-the-boettcher-function

现在它可以用作:

[Boettcher函数的级数展开公式](readme .md#series- expand -formula-of- Boettcher -function)

也可以手动操作:用连字符替换空格。

这里有一个活生生的例子