Markdown to create pages and table of contents?

后端 未结 30 2736
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 08:49

I started to use markdown to take notes.

I use marked to view my markdown notes and its beautiful.

But as my notes get longer I find it diff

30条回答
  •  醉酒成梦
    2020-12-12 09:21

    You can generate it using this bash one-liner. Assumes your markdown file is called 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
    

提交回复
热议问题