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

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

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

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

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

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


当前回答

您可以使用这个bash一行程序生成它。假设您的降价文件名为file .md。

echo "## Contents" ; echo ; 
cat FILE.md | grep '^## ' | grep -v Contents | sed 's/^## //' | 
  while read -r title ; do 
    link=$(echo $title | tr 'A-Z ' 'a-z-') ; 
    echo "- [$title](#$link)" ; 
    done

其他回答

你可以试一试。

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

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

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

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

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

我不确定,markdown的官方文件是什么? 交叉引用可以只用括号[Heading],也可以用空括号[Heading][]。

两者都使用pandoc进行工作。 所以我创建了一个快速bash脚本,它将用其TOC替换md文件中的$__TOC__。(你需要envsubst,它可能不是你发行版的一部分)

#!/bin/bash
filename=$1
__TOC__=$(grep "^##" $filename | sed -e 's/ /1. /;s/^##//;s/#/   /g;s/\. \(.*\)$/. [\1][]/')
export __TOC__
envsubst '$__TOC__' < $filename

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