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

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

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

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

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

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


当前回答

这里有一个有用的方法。应该在任何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

另一个段落

第二段文字

其他回答

对于Visual Studio Code用户来说,今天(2020年)使用的最佳选择是Markdown All in One插件(扩展)。

要安装它,启动VS Code快速打开(Control/⌘+P),粘贴以下命令,并按enter。

ext install yzhang.markdown-all-in-one

要生成TOC,打开命令面板(Control/⌘+Shift+P),并选择select Markdown:创建内容表选项。


另一个选择是Markdown TOC插件。

要安装它,启动VS Code快速打开(Control/⌘+P),粘贴以下命令,并按enter。

ext install markdown-toc

要生成TOC,打开命令面板(Control/⌘+Shift+P),并选择Markdown TOC:插入/更新选项或使用Control/⌘+MT。

使用toc.py,这是一个小的python脚本,它为你的markdown生成一个目录。

用法:

在Markdown文件中,将<toc>添加到您希望放置目录的位置。 $python toc.py README。md(使用您的markdown文件名而不是README.md)

干杯!

基于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

我使用这个网站markdown -TOC创建者,有些人可以粘贴他的整个markdown条目,网站自动创建所有必需的标签和TOC(内容表),所以有些人可以很容易地复制粘贴到他自己的文档中。

下面是一个生成目录的简单bash脚本。不需要特殊的依赖项,只需要bash。

https://github.com/Lirt/markdown-toc-bash

它可以很好地处理标题内的特殊符号,标记标题中的链接和忽略代码块。