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

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

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

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

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

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


当前回答

如果IntelliJ用户do:,命令n或控件n提供创建或更新目录的选项。参考资料:阅读此处

其他回答

您可以尝试使用这个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

我刚刚为python-markdown编写了一个扩展,它使用它的解析器来检索标题,并将TOC输出为带有本地链接的markdown格式的无序列表。文件是

Md_toc.py(是Md_toc.py)

... 它应该放在markdown安装的markdown/extensions/目录中。然后,你所要做的就是输入anchor <a> tags,带一个id="…"属性作为引用-对于这样的输入文本:

$ cat test.md 
Hello
=====

## <a id="sect one"></a>SECTION ONE ##

something here

### <a id='sect two'>eh</a>SECTION TWO ###

something else

#### SECTION THREE

nothing here

### <a id="four"></a>SECTION FOUR

also...

... 扩展可以这样调用:

$ python -m markdown -x md_toc test.md 
* Hello
    * [SECTION ONE](#sect one)
        * [SECTION TWO](#sect two)
            * SECTION THREE
        * [SECTION FOUR](#four)

... 然后您可以将这个toc粘贴回您的标记文档中(或者在您的文本编辑器中有一个快捷方式,在当前打开的文档上调用脚本,然后将结果toc插入到同一文档中)。

注意,旧版本的python-markdown没有__main__.py模块,因此,上面的命令行调用将不适用于这些版本。

有两种方法可以在你的降价文档中创建你的TOC(摘要)。

1. 手动

# My Table of content
- [Section 1](#id-section1)
- [Section 2](#id-section2)

<div id='id-section1'/>
## Section 1
<div id='id-section2'/>
## Section 2

2. 以编程方式

例如,你可以使用一个脚本,为你生成摘要,看看我的项目在github - summarizeMD -

我也尝试过其他脚本/npm模块(例如doctoc),但没有人用工作锚重现TOC。

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

用法:

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

干杯!

MultiMarkdown 4.7有一个{{TOC}}宏,用于插入一个目录表。