我开始使用标记来做笔记。

我用标记来查看我的笔记,它很漂亮。

但是随着我的笔记变长,我发现很难找到我想要的东西。

我知道markdown可以创建表,但它是否能够创建目录,跳转到部分,或定义页面部分markdown?

或者,是否有降价阅读器/编辑器可以做这些事情。搜索也是一个不错的功能。

简而言之,我想让它成为我很棒的笔记工具,功能就像写一本书一样。


当前回答

# Table of Contents
1. [Example](#example)
2. [Example2](#example2)
3. [Third Example](#third-example)

## Example [](#){name=example}
## Example2 [](#){name=example2}
## [Third Example](#){name=third-example}

如果您使用markdown extra,不要忘记您可以为链接、标题、代码围栏和图像添加特殊属性。 https://michelf.ca/projects/php-markdown/extra/#spe-attr

其他回答

你可以试一试。

# 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) 

对我来说,@Tum提出的解决方案对于2个层次的目录来说非常有效。然而,对于第3个关卡,这种方法却不起作用。它没有像前两层那样显示链接,而是显示纯文本3.5.1。[bla blabla](#blablabla) <br>代替。

我的解决方案是@Tum解决方案(非常简单)的补充,适用于需要3级或以上目录的人。

在第二层,一个简单的制表符将为您正确地完成缩进。但它不支持2个标签。相反,你必须使用一个标签,并添加尽可能多的&nbsp;根据你自己的需要来正确对齐第三层。

下面是一个使用4个关卡的例子(关卡越高,它就变得越糟糕):

# Table of Contents
1. [Title](#title) <br>
    1.1. [sub-title](#sub_title) <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1.1. [sub-sub-title](#sub_sub_title)
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

在Visual Studio Code (VSCode)中,您可以使用扩展Markdown All In One。

安装完成后,请按照以下步骤操作:

按CTRL + SHIFT + P 选择Markdown:创建目录

编辑:现在我使用DocToc来生成目录,详见我的其他答案。

您可以尝试使用这个ruby脚本从标记文件生成TOC。

 #!/usr/bin/env ruby

require 'uri'

fileName = ARGV[0]
fileName = "README.md" if !fileName

File.open(fileName, 'r') do |f|
  inside_code_snippet = false
  f.each_line do |line|
    forbidden_words = ['Table of contents', 'define', 'pragma']
    inside_code_snippet = !inside_code_snippet if line.start_with?('```')
    next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } || inside_code_snippet

    title = line.gsub("#", "").strip
    href = URI::encode title.gsub(" ", "-").downcase
    puts "  " * (line.count("#")-1) + "* [#{title}](\##{href})"
  end
end

你可以使用DocToc从命令行生成目录:

doctoc /path/to/file

要使链接与Bitbucket生成的锚点兼容,请使用——Bitbucket参数运行它。