我正在编写一个大型Markdown文档,并希望在开始时放置一个目录,将提供到文档中各个位置的链接。我该怎么做呢?
我试着用:
[a link](# MyTitle)
其中MyTitle是文档中的一个标题,但这不起作用。
我正在编写一个大型Markdown文档,并希望在开始时放置一个目录,将提供到文档中各个位置的链接。我该怎么做呢?
我试着用:
[a link](# MyTitle)
其中MyTitle是文档中的一个标题,但这不起作用。
当前回答
只需遵循[text](#link)语法并遵循以下指导原则:
把字母和数字原封不动地写下来 用破折号-替换空格 删除其余的字符
举个例子,如果你有这些部分:
# 1. Python
# 2. c++
# 3. c++11
# 4. asp.net-core
您可以使用以下命令添加引用:
[1. Python](#1-python)
[2. c++](#2-c)
[3. c++11](#3-c11)
[4. asp.net-core](#4-aspnet-core)
注意asp.net-core如何变成aspnet-core, 1。Python变成了1-python,等等。
其他回答
一些额外的事情要记住,如果你曾经在你想导航到的标题中的符号…
# What this is about
------
#### Table of Contents
- [About](#what-this-is-about)
- [⚡ Sunopsis](#9889-tldr)
- [:gear: Grinders](#it-grinds-my-gears)
- [Attribution]
------
## ⚡ TLDR
Words for those short on time or attention.
___
## It Grinds my :gear:s
Here _`:gear:`_ is not something like ⚙ or ⛭
___
## ⛤ 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方式,要么为各种巧妙的方式添加配置和脚本逻辑,比如清理标题的文本。
只需遵循[text](#link)语法并遵循以下指导原则:
把字母和数字原封不动地写下来 用破折号-替换空格 删除其余的字符
举个例子,如果你有这些部分:
# 1. Python
# 2. c++
# 3. c++11
# 4. asp.net-core
您可以使用以下命令添加引用:
[1. Python](#1-python)
[2. c++](#2-c)
[3. c++11](#3-c11)
[4. asp.net-core](#4-aspnet-core)
注意asp.net-core如何变成aspnet-core, 1。Python变成了1-python,等等。
是的,markdown确实做到了这一点,但你需要指定名称anchor <a name='xyx'>。
一个完整的例子,
这就创建了链接 (任务)(#任务)
在文档的其他地方,您创建了命名锚(不管它叫什么)。
<a name="tasks">
my tasks
</a>
注意,你也可以把它环绕在标题上。
<a name="tasks">
### Agile tasks (created by developer)
</a>
因为在评论中提到了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.
pandoc手册解释了如何使用头文件的标识符链接到头文件。我没有检查其他解析器对此的支持,但据报道,它不能在github上工作。
标识符可以手动指定:
## my heading text {#mht}
Some normal text here,
including a [link to the header](#mht).
或者您可以使用自动生成的标识符(在本例中是#my-heading-text)。在pandoc手册中都有详细的解释。
注意:这只适用于转换为HTML, LaTex, ConTeXt, Textile或AsciiDoc。