我开始使用标记来做笔记。
我用标记来查看我的笔记,它很漂亮。
但是随着我的笔记变长,我发现很难找到我想要的东西。
我知道markdown可以创建表,但它是否能够创建目录,跳转到部分,或定义页面部分markdown?
或者,是否有降价阅读器/编辑器可以做这些事情。搜索也是一个不错的功能。
简而言之,我想让它成为我很棒的笔记工具,功能就像写一本书一样。
我开始使用标记来做笔记。
我用标记来查看我的笔记,它很漂亮。
但是随着我的笔记变长,我发现很难找到我想要的东西。
我知道markdown可以创建表,但它是否能够创建目录,跳转到部分,或定义页面部分markdown?
或者,是否有降价阅读器/编辑器可以做这些事情。搜索也是一个不错的功能。
简而言之,我想让它成为我很棒的笔记工具,功能就像写一本书一样。
当前回答
只需要增加幻灯片的数量!它与markdown ioslides和revealjs演示一起工作
## Table of Contents
1. [introduction](#3)
2. [section one](#5)
其他回答
对我来说,@Tum提出的解决方案对于2个层次的目录来说非常有效。然而,对于第3个关卡,这种方法却不起作用。它没有像前两层那样显示链接,而是显示纯文本3.5.1。[bla blabla](#blablabla) <br>代替。
我的解决方案是@Tum解决方案(非常简单)的补充,适用于需要3级或以上目录的人。
在第二层,一个简单的制表符将为您正确地完成缩进。但它不支持2个标签。相反,你必须使用一个标签,并添加尽可能多的 根据你自己的需要来正确对齐第三层。
下面是一个使用4个关卡的例子(关卡越高,它就变得越糟糕):
# Table of Contents
1. [Title](#title) <br>
1.1. [sub-title](#sub_title) <br>
1.1.1. [sub-sub-title](#sub_sub_title)
1.1.1.1. [sub-sub-sub-title](#sub_sub_sub_title)
# Title <a name="title"></a>
Heading 1
## Sub-Title <a name="sub_title"></a>
Heading 2
### Sub-Sub-Title <a name="sub_sub_title"></a>
Heading 3
#### Sub-Sub-Sub-Title <a name="sub_sub_sub_title"></a>
Heading 4
这将给出以下结果,其中目录表的每个元素都是到其相应部分的链接。还要注意<br>,以便添加新行,而不是在同一行上。
目录
标题 1.1. 字幕 1.1.1。Sub-Sub-Title 1.1.1.1。Sub-Sub-Sub-Title
标题
标题1
字幕
标题2
Sub-Sub-Title
标题3
Sub-Sub-Sub-Title标题4
只需要增加幻灯片的数量!它与markdown ioslides和revealjs演示一起工作
## Table of Contents
1. [introduction](#3)
2. [section one](#5)
这里有一个有用的方法。应该在任何MarkDown编辑器中产生可点击的引用。
# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)
## This is the introduction <a name="introduction"></a>
Some introduction text, formatted in heading 2 style
## Some paragraph <a name="paragraph1"></a>
The first paragraph text
### Sub paragraph <a name="subparagraph1"></a>
This is a sub paragraph, formatted in heading 3 style
## Another paragraph <a name="paragraph2"></a>
The second paragraph text
生产:
目录
简介 一些段落 子段 另一个段落
这是介绍
一些介绍文本,格式为标题2的风格
一些段落
第一段文字
子段
这是一个子段落,格式为标题3
另一个段落
第二段文字
你可以试一试。
# Table of Contents
1. [Example](#example)
2. [Example2](#example2)
3. [Third Example](#third-example)
4. [Fourth Example](#fourth-examplehttpwwwfourthexamplecom)
## Example
## Example2
## Third Example
## [Fourth Example](http://www.fourthexample.com)
基于albertodebortoli answer创建了附加检查和标点符号替换功能。
# @fn def generate_table_of_contents markdown # {{{
# @brief Generates table of contents for given markdown text
#
# @param [String] markdown Markdown string e.g. File.read('README.md')
#
# @return [String] Table of content in markdown format.
#
def generate_table_of_contents markdown
table_of_contents = ""
i_section = 0
# to track markdown code sections, because e.g. ruby comments also start with #
inside_code_section = false
markdown.each_line do |line|
inside_code_section = !inside_code_section if line.start_with?('```')
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?('#') || inside_code_section || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.gsub("#", "").strip
href = title.gsub(/(^[!.?:\(\)]+|[!.?:\(\)]+$)/, '').gsub(/[!.,?:; \(\)-]+/, "-").downcase
bullet = line.count("#") > 1 ? " *" : "#{i_section += 1}."
table_of_contents << " " * (line.count("#") - 1) + "#{bullet} [#{title}](\##{href})\n"
end
table_of_contents
end