LoginSignup
129
88

More than 1 year has passed since last update.

【vscode】Markdownにおける目次(TOC)の作成に、Markdown All in Oneが便利だった件

Posted at

はじめに

vscode にて、見出し (Heading) の内容に基づく目次(TOC, Table Of Contents)の作成方法を紹介します。

目次の作成には、Markdown All in Oneという拡張機能のTable of contentsを使います。
この目次は、見出しの変更に伴い自動で更新されます。

デモ

  • コマンドパレットでMarkdown All in One: Create Table of Contentsを実行すると、見出しの内容から目次が作成される
  • 見出し更新後にctrl+sで保存すると、目次も更新される

vscode_toc_01.gif

インストール

  1. ctrl+p -> ext install Markdown All in One
  2. Markdown All in Oneをインストール

機能

目次の作成

ctrl+shift+p -> Markdown All in One: Create Table of Contents

目次の更新

  • ctrl+Sで保存
    • markdown.extension.toc.updateOnSave設定を切ることで、無効化も可能
  • ctrl+shift+p -> Markdown All in One: Update Table of Contents

特定の見出しを目次から除外する

<!-- omit in toc -->を使います。
以下の場合、## Table of Contentsが目次から除外されます。

# Introduction

## Table of Contents <!-- omit in toc -->

- [Introduction](#introduction)
  - [Section 1](#section-1)

## Section 1

markdown.extension.toc.omittedFromToc設定を使い、User/Workspace 全体で一部の見出しを除外できます。

// In your settings.json
"markdown.extension.toc.omittedFromToc": {
  // Use a path relative to your workspace.
  "README.md": [
      "# Introduction",
      "## Also omitted",
  ],
  // Or an absolute path for standalone files.
  "/home/foo/Documents/todo-list.md": [
    "## Shame list (I'll never do these)",
  ]
}

セクション番号の追加/削除

目次を作成する際、見出しは一意である必要があります。
その際、セクション番号を使用すると、簡単に一意の見出しを用意できます。

ctrl+shift+p -> Markdown All in One: Add/Update section numbers

section-numbers.gif

見出しを追加した際も、上記のコマンドを実行することにより自動でセクション番号が更新されます。

参考

Markdown All in One - Visual Studio Marketplace

129
88
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
129
88