我开始使用标记来做笔记。
我用标记来查看我的笔记,它很漂亮。
但是随着我的笔记变长,我发现很难找到我想要的东西。
我知道markdown可以创建表,但它是否能够创建目录,跳转到部分,或定义页面部分markdown?
或者,是否有降价阅读器/编辑器可以做这些事情。搜索也是一个不错的功能。
简而言之,我想让它成为我很棒的笔记工具,功能就像写一本书一样。
我开始使用标记来做笔记。
我用标记来查看我的笔记,它很漂亮。
但是随着我的笔记变长,我发现很难找到我想要的东西。
我知道markdown可以创建表,但它是否能够创建目录,跳转到部分,或定义页面部分markdown?
或者,是否有降价阅读器/编辑器可以做这些事情。搜索也是一个不错的功能。
简而言之,我想让它成为我很棒的笔记工具,功能就像写一本书一样。
当前回答
MultiMarkdown Composer似乎生成了一个目录来辅助编辑。
也可能存在这样或那样的库,它们可以生成TOC:参见Python Markdown TOC扩展。
其他回答
# 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
这是一个简短的PHP代码,我用来生成TOC,并丰富任何标题与锚:
$toc = []; //initialize the toc to an empty array
$markdown = "... your mardown content here...";
$markdown = preg_replace_callback("/(#+)\s*([^\n]+)/",function($matches) use (&$toc){
static $section = [];
$h = strlen($matches[1]);
@$section[$h-1]++;
$i = $h;
while(isset($section[$i])) unset($section[$i++]);
$anchor = preg_replace('/\s+/','-', strtolower(trim($matches[2])));
$toc[] = str_repeat(' ',$h-1)."* [".implode('.',$section).". {$matches[2]}](#$anchor)";
return str_repeat('#',$h)." <strong>".implode('.',$section).".</strong> ".$matches[2]."\n<a name=\"$anchor\"></a>\n";
}, $markdown);
然后你可以打印经过处理的markdown和toc:
print(implode("\n",$toc));
print("\n\n");
print($markdown);
在Visual Studio Code (VSCode)中,您可以使用扩展Markdown All In One。
安装完成后,请按照以下步骤操作:
按CTRL + SHIFT + P 选择Markdown:创建目录
编辑:现在我使用DocToc来生成目录,详见我的其他答案。
对我来说,@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
你可以试一试。
# 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)