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

我试着用:

[a link](# MyTitle)

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


当前回答

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。

其他回答

因为在评论中提到了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.

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)

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

这里有一个活生生的例子

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

在pandoc中,如果在生成html时使用——toc选项,将生成一个包含到章节的链接的目录,并从章节标题返回到目录。它类似于pandoc编写的其他格式,如LaTeX、rtf、rst等。对于命令

pandoc --toc happiness.txt -o happiness.html

这里有一点降价:

% True Happiness

Introduction
------------

Many have posed the question of true happiness.  In this blog post we propose to
solve it.

First Attempts
--------------

The earliest attempts at attaining true happiness of course aimed at pleasure. 
Soon, though, the downside of pleasure was revealed.

将产生这个作为html的主体:

<h1 class="title">
    True Happiness
</h1>
<div id="TOC">
    <ul>
        <li>
            <a href="#introduction">Introduction</a>
        </li>
        <li>
            <a href="#first-attempts">First Attempts</a>
        </li>
    </ul>
</div>
<div id="introduction">
    <h2>
        <a href="#TOC">Introduction</a>
    </h2>
    <p>
        Many have posed the question of true happiness. In this blog post we propose to solve it.
    </p>
</div>
<div id="first-attempts">
    <h2>
        <a href="#TOC">First Attempts</a>
    </h2>
    <p>
        The earliest attempts at attaining true happiness of course aimed at pleasure. Soon, though, the downside of pleasure was revealed.
    </p>
</div>

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。