我正在编写一个大型Markdown文档,并希望在开始时放置一个目录,将提供到文档中各个位置的链接。我该怎么做呢?
我试着用:
[a link](# MyTitle)
其中MyTitle是文档中的一个标题,但这不起作用。
我正在编写一个大型Markdown文档,并希望在开始时放置一个目录,将提供到文档中各个位置的链接。我该怎么做呢?
我试着用:
[a link](# MyTitle)
其中MyTitle是文档中的一个标题,但这不起作用。
当前回答
一些额外的事情要记住,如果你曾经在你想导航到的标题中的符号…
# 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方式,要么为各种巧妙的方式添加配置和脚本逻辑,比如清理标题的文本。
其他回答
在我的情况下,我正在寻找一个没有Pandoc的TOC解决方案。每个TOC条目都包含一个指向标题的链接,格式为[显示名称](#-url- formatting - Name -of-header)
对于2个缩进级别的简单情况,
1. [Installation](#1-installation)
1.1. [Minimum System Requirements](#11-minimum-system-requirements)
1.2. [Prerequisites](#12-prerequisites)
结果:
安装 1.1. 系统最低要求 1.2. 先决条件
对于包含3个或更多缩进级别的一般多级编号列表,列表无法在第3级或更高级别进一步缩进(例如1.3.2.)。相反,我能找到的最好的解决方案是使用>>>来格式化嵌套的blockquotes。
## Table of Contents
>1. [Installation](#1-installation)
>>1.1. [Minimum System Requirements](#11-minimum-system-requirements)
>>1.2. [Prerequisites](#12-prerequisites)
>>>1.2.1. [Preparation of Database Server](#121-preparation-of-database-server)
>>>1.2.2. [Preparation of Other Servers](#122-preparation-of-other-servers)
>>
>>1.3. [Installing – Single Server](#13-installing-single-server)
>>1.4. [Installing – Multi Server](#14-installing-multi-server)
>>>1.4.1. [Database Server](#141-database-server)
>>>...
结果在GitHub上很好地渲染TOC。不能渲染它在这里没有SO的linter抱怨未格式化的代码。
注意1.2.2之后的空白条目。 如果没有空白条目,下面的行仍然停留在第3个blockquote缩进级别。
相比之下,项目列表只使用空格或制表符作为缩进标记
## Table of Contents
- [Installation](#1-installation)
- [Minimum System Requirements](#11-minimum-system-requirements)
- [Prerequisites](#12-prerequisites)
- [Preparation of Database Server](#121-preparation-of-database-server)
- [Preparation of Other Servers](#122-preparation-of-other-servers)
- [Installing – Single Server](#13-installing-single-server)
- [Installing – Multi Server](#-installing-multi-server)
- [Database Server](#141-database-server)
- ...
结果:
目录
安装 系统最低要求 先决条件 数据库服务器准备 其他服务器准备 安装—单机 安装-多服务器 数据库服务器 ...
所有上述缩进列表将成功链接到以下标题在GitHub markdown(标题无法链接在so风味markdown出于某种原因)-
# 1. Installation
## 1.1. Minimum System Requirements
## 1.2. Prerequisites
### 1.2.1. Preparation of Database Server
### 1.2.2. Preparation of Other Servers
## 1.3. Installing – Single Server
## 1.4. Installing – Multi Server
### 1.4.1. Database Server
在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>
在Markdown规范中没有这样的指令,抱歉。
关于<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