如何在Markdown中链接到同一文档的一部分? [英] How to link to part of the same document in Markdown?

查看:171
本文介绍了如何在Markdown中链接到同一文档的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个大型的Markdown文档,并希望在开始时放置一个目录列表,该目录将提供指向文档中各个位置的链接.我该怎么办?

I am writing a large Markdown document and would like to place a table of contents of sorts at the beginning that will provide links to various locations in the document. How can I do this?

我尝试使用

[a link](# MyTitle)

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

where MyTitle is a title within the document and this didn't work.

推荐答案

pandoc 中如果在生成html中使用选项--toc,则会生成目录,其中包含指向各节的链接,并从节标题返回该目录.它与pandoc编写的其他格式(例如LaTeX,rtf,rst等)相似.因此,使用命令

In pandoc, if you use the option --toc in producing html, a table of contents will be produced with links to the sections, and back to the table of contents from the section headings. It is similar with the other formats pandoc writes, like LaTeX, rtf, rst, etc. So with the command

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的正文:

will yield this as the body of the 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>

这篇关于如何在Markdown中链接到同一文档的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆