Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9038

doctocコマンドでMarkdownに目次を作成する

$
0
0
doctocとは、markdownファイルの目次を自動的に生成するCLIです。 Node.jsで記載されています。 thlorenz/doctoc: 📜 Generates table of contents for markdown files inside local git repository. Links are compatible with anchors generated by github or other sites. インストール npmでインストールする場合 npm install -g doctoc 使い方 Sample doctoc.md # doctoc test ## test1 ### test1-1 ### test1-2 #### test1-2-1 ## test2 ### test2-1 上記のdoctoc.mdに以下のコマンドで目次を作成します。 $ doctoc doctoc.md DocToccing single file "doctoc.md" for github.com. ================== "doctoc.md" will be updated Everything is OK. Everything is OK.と出力されると、ファイルに目次が追記されています。 doctoc.md <!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - [doctoc test](#doctoc-test) - [test1](#test1) - [test1-1](#test1-1) - [test1-2](#test1-2) - [test1-2-1](#test1-2-1) - [test2](#test2) - [test2-1](#test2-1) <!-- END doctoc generated TOC please keep comment here to allow auto update --> # doctoc test ## test1 ### test1-1 ### test1-2 #### test1-2-1 ## test2 ### test2-1 <!-- START doctoc generated TOC please keep comment here to allow auto update -->から <!-- END doctoc generated TOC please keep comment here to allow auto update -->までが doctocによって自動的に追加された目次になります。 2行目に警告が記載されてますが、doctocで追記された部分は編集しないようにしてください。 markdownの内容を更新して、doctocを再実行したときにうまく作成されない恐れがあります。 オプションについて よく使うのは以下のオプションです。 オプション 内容 [--notitle, --title title] **Table of Contents**の行の有無、もしくは名前の指定 [--maxlevel level] 追記する目次の深さ [-s, --stdout] 作成時のコマンド出力に目次を表示する 使用するサイトのmarkdown形式に合わせたオプション --bitbucket bitbucket.org --nodejs nodejs.org --github github.com --gitlab gitlab.com --ghost ghost.org 特定ファイルをSkipしたい場合 公式サイトによるとmarkdownファイルの先頭に<!-- DOCTOC SKIP -->と記載する必要がある。 skip.md <!-- DOCTOC SKIP --> # doctoc test ## test1 ### test1-1 ### test1-2 #### test1-2-1 ## test2 ### test2-1 次に以下のコマンドを実行する。 ack -L 'DOCTOC SKIP' | xargs doctoc 単純に、DOCTOC SKIPという文字列が入っていないファイルに対して目次を作成しているだけである。

Viewing all articles
Browse latest Browse all 9038

Trending Articles