2013-10-12
OmniMarkupPreviewer で目次を表示する
Markdown の原稿で目次が出せたらいいなとおもって調べてたら以下の記事に出会った。
SublimeText2でMarkdownにTOCを挿入する
http://bellonieta.net/2013/05/sublimetext2でmarkdownにtocを挿入する/
SublimeTextで使ってたのは OmniMarkupPreviewer だったからこれでも拡張できるのかも??とおもったので設定ファイルを眺めてみた。
Preferences > Package Settings > OmniMarkupPreviewer > Setting - Default
で開く設定ファイルのなかに
// MarkdownRenderer options
"renderer_options-MarkdownRenderer": {
// Valid extensions:
// - OFFICIAL (Python Markdown) -
// "extra": Combines ["abbr", "attr_list", "def_list", "fenced_code", "footnotes", "tables", "smart_strong"]
// For PHP Markdown Extra(http://michelf.ca/projects/php-markdown/extra/)
// "abbr": http://packages.python.org/Markdown/extensions/abbreviations.html
// "attr_list": http://packages.python.org/Markdown/extensions/attr_list.html
// "def_list": http://packages.python.org/Markdown/extensions/definition_lists.html
// "fenced_code": http://packages.python.org/Markdown/extensions/fenced_code_blocks.html
// "footnotes": http://packages.python.org/Markdown/extensions/footnotes.html
// "tables": http://packages.python.org/Markdown/extensions/tables.html
// "smart_strong": http://packages.python.org/Markdown/extensions/smart_strong.html
// "codehilite": http://packages.python.org/Markdown/extensions/code_hilite.html
// "meta": http://packages.python.org/Markdown/extensions/meta_data.html
// "toc": http://packages.python.org/Markdown/extensions/toc.html
// "nl2br": http://packages.python.org/Markdown/extensions/nl2br.html
// - 3RD PARTY -
// "strikeout": Strikeout extension syntax - `This ~~is deleted text.~~`
// "subscript": Subscript extension syntax - `This is water: H~2~O`
// "superscript": Superscript extension syntax 0 `2^10^ = 1024`
// "smartypants": Python-Markdown extension using smartypants to emit
// typographically nicer ("curly") quotes, proper
// ("em" and "en") dashes, etc.
// See: https://bitbucket.org/jeunice/mdx_smartypants
"extensions": ["tables", "strikeout", "fenced_code", "codehilite"]
っていう部分があって
// MarkdownRenderer options
"renderer_options-MarkdownRenderer": {
// Valid extensions:
// - OFFICIAL (Python Markdown) -
// "extra": Combines ["abbr", "attr_list", "def_list", "fenced_code", "footnotes", "tables", "smart_strong"]
// For PHP Markdown Extra(http://michelf.ca/projects/php-markdown/extra/)
// "abbr": http://packages.python.org/Markdown/extensions/abbreviations.html
// "attr_list": http://packages.python.org/Markdown/extensions/attr_list.html
// "def_list": http://packages.python.org/Markdown/extensions/definition_lists.html
// "fenced_code": http://packages.python.org/Markdown/extensions/fenced_code_blocks.html
// "footnotes": http://packages.python.org/Markdown/extensions/footnotes.html
// "tables": http://packages.python.org/Markdown/extensions/tables.html
// "smart_strong": http://packages.python.org/Markdown/extensions/smart_strong.html
// "codehilite": http://packages.python.org/Markdown/extensions/code_hilite.html
// "meta": http://packages.python.org/Markdown/extensions/meta_data.html
// "toc": http://packages.python.org/Markdown/extensions/toc.html
// "nl2br": http://packages.python.org/Markdown/extensions/nl2br.html
// - 3RD PARTY -
// "strikeout": Strikeout extension syntax - `This ~~is deleted text.~~`
// "subscript": Subscript extension syntax - `This is water: H~2~O`
// "superscript": Superscript extension syntax 0 `2^10^ = 1024`
// "smartypants": Python-Markdown extension using smartypants to emit
// typographically nicer ("curly") quotes, proper
// ("em" and "en") dashes, etc.
// See: https://bitbucket.org/jeunice/mdx_smartypants
"extensions": ["tables", "strikeout", "fenced_code", "codehilite","toc"]
ってかんじで、「,"toc"」を追加してみた。
Table of Contents Extension — Python Markdown
http://pythonhosted.org/Markdown/extensions/toc.html
をみてみると、
[TOC]
と記述すると目次が出来るみたいなので、それを .md のファイルに入れてみたら目次が出た。
なんと便利なんでしょ。
目次を出す階層を指定出来たりするといいんだろうけど、これでひとまず十分。
仕様書とか、テキストだけだとキツイかもしれないけど、1箇所に集中してまとめとくとかするときはこれでもいいなぁ。