├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── ISSUE_TEMPLATE
│ ├── feature.md
│ └── question.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .markdownlint.json
├── .python-version
├── .travis.yml
├── LICENSE-MIT
├── Main.sublime-menu
├── MarkdownTOC.sublime-commands
├── MarkdownTOC.sublime-settings
├── README.md
├── Vagrantfile
├── __init__.py
├── appveyor.yml
├── images
├── capture.gif
├── how_to_remove_the_toc.gif
└── title.gif
├── markdowntoc
├── __init__.py
├── autorunner.py
├── base.py
├── id.py
├── markdowntoc_insert.py
├── markdowntoc_update.py
└── util.py
├── messages.json
├── messages
├── 1.2.1.md
├── 1.3.0.md
├── 1.4.0.md
├── 1.5.0.md
├── 1.6.0.md
├── 1.7.0.md
├── 1.8.0.md
├── 2.0.0.md
├── 2.1.0.md
├── 2.1.1.md
├── 2.1.2.md
├── 2.2.0.md
├── 2.2.1.md
├── 2.3.0.md
├── 2.3.1.md
├── 2.3.2.md
├── 2.4.0.md
├── 2.4.1.md
├── 2.5.0.md
├── 2.6.0.md
├── 2.7.0.md
├── 2.7.1.md
├── 2.7.2.md
├── 2.7.3.md
├── 2.8.0.md
├── 3.0.0.md
├── 3.0.1.md
├── 3.0.2.md
├── 3.0.3.md
├── 3.0.4.md
├── 3.0.5.md
├── 4.0.0.md
├── 4.0.1.md
├── 4.0.2.md
├── 4.1.0.md
├── 4.1.1.md
├── 4.1.2.md
└── install.md
├── tests
├── autoanchor.py
├── autolink.py
├── base.py
├── bracket.py
├── default.py
├── exclude_heading.py
├── github_flavored_markdown.py
├── indent.py
├── italic_in_heading.py
├── levels.py
├── link_prefix.py
├── list_bullets.py
├── lowercase.py
├── markdown_preview.py
├── quotes_in_attributes.py
├── remove_image.py
├── style.py
├── tag_variation.py
└── uri_encoding.py
└── unittesting.json
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | These are the guidelines for contributing to this repository.
4 |
5 | ## Issues
6 |
7 | Please use the template for your type of issue.
8 |
9 | - [Bug Report](https://github.com/naokazuterada/MarkdownTOC/issues/new)
10 | - [Feature Request](https://github.com/naokazuterada/MarkdownTOC/issues/new?template=feature.md)
11 | - [Question](https://github.com/naokazuterada/MarkdownTOC/issues/new?template=question.md)
12 |
13 | ### Way of operation
14 |
15 | 1. The maintainers will `Close` the issue or PR
16 | 1. Not accepted feature request
17 | - Add the `wontfix` label
18 | 2. Not clear or unresponsive
19 | - Not clear: Problem is not obvious or not reproducible.
20 | - Unresponsive: the author does not respond to inquiries within 3 weeks.
21 |
22 | ## Gitter
23 |
24 | If you want more general support or to ask questions, please use [Gitter](https://gitter.im/naokazuterada/MarkdownTOC) chat system.
25 |
26 | ## Patches
27 |
28 | Patches for fixes, features, and improvements are accepted via pull requests.
29 |
30 | Pull requests should be based on the master branch, unless you want to contribute to an active branch for a specific topic.
31 |
32 | ### Coding Style
33 |
34 | You should use [Black](https://github.com/psf/black) for automatic code formatting.
35 |
36 | ```
37 | pip install black
38 | black .
39 | ```
40 |
41 | ### Test
42 |
43 | You should use unit-tests for SublimeText by using [UnitTesting](https://github.com/randy3k/UnitTesting) plugin.
44 |
45 | 1. Install the UnitTesting plugin
46 | 2. Comment out or rename your own `MarkdownTOC.sublime-settings` so individual settings are not used during testing
47 | 3. [Run tests](https://github.com/randy3k/UnitTesting-example#running-tests)
48 | 4. Send Pull Request when tests pass
49 |
50 | All contributions are welcome
51 |
52 | ## Useful Tools
53 |
54 | - [Gyazo](https://gyazo.com/en): Tool for making animated GIFs from screen captures. Use it for showing how the function works.
55 |
56 | ## Licensing and copyright
57 |
58 | Please note that accepted contributions are included in the repository and hence under the same license as the repository contributed to.
59 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
18 |
19 | # How can the issue be reproduced
20 |
21 | # What was expected
22 |
23 | # What actually occurred
24 |
25 | # What was the version of the involved component
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature.md:
--------------------------------------------------------------------------------
1 |
18 |
19 | # Purpose
20 |
21 | # How important it is
22 |
23 | # Ideal implementation
24 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 |
18 |
19 | # Question
20 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | package-metadata.json
2 | .DS_Store
3 | .vagrant
4 | *.pyc
5 | *.pyo
--------------------------------------------------------------------------------
/.markdownlint.json:
--------------------------------------------------------------------------------
1 | {
2 | "first-line-h1": false,
3 | "line-length": false,
4 | "html": false,
5 | "blanks-around-headings": false,
6 | "heading-style": false,
7 | "ul-indent": false,
8 | "blanks-around-fences": false
9 | }
10 |
--------------------------------------------------------------------------------
/.python-version:
--------------------------------------------------------------------------------
1 | 3.8
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | env:
2 | global:
3 | - PACKAGE="MarkdownTOC" # Package name
4 | - SUBLIME_TEXT_VERSION="3"
5 | # use UNITTESTING_TAG to specific tag of UnitTesting
6 | # - UNITTESTING_TAG="master"
7 |
8 | # mutliple os matrix
9 | # https://docs.travis-ci.com/user/multi-os/#Python-example-(unsupported-languages)
10 | matrix:
11 | include:
12 | - os: linux
13 | services: xvfb
14 | language: python
15 | python: 3.7
16 | - os: osx
17 | language: generic
18 |
19 |
20 | before_install:
21 | - curl -OL https://raw.githubusercontent.com/SublimeText/UnitTesting/master/sbin/travis.sh
22 | # enable gui, see https://docs.travis-ci.com/user/gui-and-headless-browsers
23 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then
24 | export DISPLAY=:99.0;
25 | sh -e /etc/init.d/xvfb start;
26 | sleep 3;
27 | fi
28 |
29 | install:
30 | # bootstrap the testing environment
31 | - sh travis.sh bootstrap
32 | # install Package Control and package denepdencies
33 | # - sh travis.sh install_package_control
34 |
35 | script:
36 | # run tests with test coverage report
37 | - sh travis.sh run_tests --coverage
38 | # testing syntax_test files
39 | # - sh travis.sh run_syntax_tests
40 |
41 | after_success:
42 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then
43 | brew update;
44 | brew install python3;
45 | pip3 install codecov;
46 | fi
47 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then
48 | pip install codecov;
49 | fi
50 | - codecov -t e41883b8-547a-4728-a703-d8e1bbedfcf8
51 |
52 | notifications:
53 | email: true
54 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2013 Naokazu Terada
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/Main.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "id": "tools",
4 | "children":
5 | [
6 | {
7 | "caption": "MarkdownTOC",
8 | "children":
9 | [
10 | {
11 | "caption": "Insert TOC",
12 | "command": "markdowntoc_insert"
13 | },
14 | {
15 | "caption": "Update TOC",
16 | "command": "markdowntoc_update"
17 | }
18 | ]
19 | }
20 | ]
21 | },
22 | {
23 | "caption": "Preferences",
24 | "mnemonic": "n",
25 | "id": "preferences",
26 | "children":
27 | [
28 | {
29 | "caption": "Package Settings",
30 | "mnemonic": "P",
31 | "id": "package-settings",
32 | "children":
33 | [
34 | {
35 | "caption": "MarkdownTOC Settings",
36 | "command": "edit_settings",
37 | "args": {"base_file": "${packages}/MarkdownTOC/MarkdownTOC.sublime-settings"},
38 | }
39 | ]
40 | }
41 | ]
42 | }
43 | ]
--------------------------------------------------------------------------------
/MarkdownTOC.sublime-commands:
--------------------------------------------------------------------------------
1 | [
2 | { "caption": "MarkdownTOC:Insert TOC", "command": "markdowntoc_insert" },
3 | { "caption": "MarkdownTOC:Update TOC", "command": "markdowntoc_update" }
4 | ]
--------------------------------------------------------------------------------
/MarkdownTOC.sublime-settings:
--------------------------------------------------------------------------------
1 | {
2 | "defaults": {
3 | "autoanchor": false,
4 | "autolink": false,
5 | "bracket": "round",
6 | "levels": [1,2,3,4,5,6],
7 | "indent": "\t",
8 | "remove_image": true,
9 | "link_prefix": "",
10 | "bullets": ["-"],
11 | "lowercase": "only_ascii",
12 | "style": "unordered",
13 | "uri_encoding": true,
14 | "markdown_preview": ""
15 | },
16 | "id_replacements": [
17 | {
18 | "pattern": "\\s+",
19 | "replacement": "-"
20 | },
21 | {
22 | "pattern": "<|>|&|'|"|<|>|&|'|"|!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|\\?|@|\\[|\\]|`|\"|\\.|\\\\|<|>|{|}|™|®|©|%",
23 | "replacement": ""
24 | }
25 | ],
26 | "logging": false
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | 
4 |
5 | MarkdownTOC
6 | ===========
7 |
8 | Sublime Text 3 plugin for generating a Table of Contents (TOC) in a Markdown document.
9 |
10 | [](https://travis-ci.org/naokazuterada/MarkdownTOC) [](https://ci.appveyor.com/project/naokazuterada/markdowntoc/branch/master) [](https://codecov.io/gh/naokazuterada/MarkdownTOC) [](https://packagecontrol.io/packages/MarkdownTOC) [](https://gitter.im/naokazuterada/MarkdownTOC)
11 |
12 | ---
13 |
14 | ***Note: v3.0.0 has breaking changes. See [Upgrade Guide](https://github.com/naokazuterada/MarkdownTOC/releases/tag/3.0.0) for more detail.***
15 |
16 | ---
17 |
18 | ## Table of Contents
19 |
20 |
21 | Click to open TOC
22 |
23 |
24 | - [Quick Start](#quick-start)
25 | - [Features](#features)
26 | - [Insertion of TOC based on headings in Markdown document](#insertion-of-toc-based-on-headings-in-markdown-document)
27 | - [Automatic refresh of TOC when Markdown document is saved](#automatic-refresh-of-toc-when-markdown-document-is-saved)
28 | - [Supported file extensions](#supported-file-extensions)
29 | - [Customizing generation of TOC using attributes](#customizing-generation-of-toc-using-attributes)
30 | - [Auto anchoring when heading has anchor defined](#auto-anchoring-when-heading-has-anchor-defined)
31 | - [Auto linking for _clickable_ TOC](#auto-linking-for-_clickable_-toc)
32 | - [Lowercasing in ids](#lowercasing-in-ids)
33 | - [Preserve case](#preserve-case)
34 | - [Lowercase all characters](#lowercase-all-characters)
35 | - [Manipulation of auto link ids](#manipulation-of-auto-link-ids)
36 | - [URI encoding](#uri-encoding)
37 | - [Markdown Preview compatible](#markdown-preview-compatible)
38 | - [Link Prefix](#link-prefix)
39 | - [Control of levels listed in TOC](#control-of-levels-listed-in-toc)
40 | - [Ordered or unordered style for TOC elements](#ordered-or-unordered-style-for-toc-elements)
41 | - [Customizable list bullets in TOC](#customizable-list-bullets-in-toc)
42 | - [Specify custom indentation prefix](#specify-custom-indentation-prefix)
43 | - [Preserve images in headings](#preserve-images-in-headings)
44 | - [Excluded headings](#excluded-headings)
45 | - [Usage](#usage)
46 | - [Tips](#tips)
47 | - [How to remove anchors added by MarkdownTOC](#how-to-remove-anchors-added-by-markdowntoc)
48 | - [Addressing issues with Github Pages](#addressing-issues-with-github-pages)
49 | - [Using MarkdownTOC with Markdownlint](#using-markdowntoc-with-markdownlint)
50 | - [Limitations](#limitations)
51 | - [Headings in lists are not included in the auto-generated table of contents](#headings-in-lists-are-not-included-in-the-auto-generated-table-of-contents)
52 | - [Attributes](#attributes)
53 | - [Installation](#installation)
54 | - [Using Package Control](#using-package-control)
55 | - [From Git](#from-git)
56 | - [From downloadable archive](#from-downloadable-archive)
57 | - [Configuration](#configuration)
58 | - [Github Configuration](#github-configuration)
59 | - [Configuration and Collaboration](#configuration-and-collaboration)
60 | - [Compatibility](#compatibility)
61 | - [Contributing](#contributing)
62 | - [License](#license)
63 | - [Author](#author)
64 | - [References](#references)
65 | - [Markdown Table of Contents Generators](#markdown-table-of-contents-generators)
66 | - [Recommended plugins for use with MarkdownTOC](#recommended-plugins-for-use-with-markdowntoc)
67 |
68 |
69 |
70 |
71 | ## Quick Start
72 |
73 | 1. [Install](#installation) the **MarkdownTOC** plugin
74 | 1. Open your [Markdown] file
75 | 1. Place the cursor at the position where you want to insert the TOC
76 | 1. Pick from menu: Tools > MarkdownTOC > Insert TOC
77 | 1. And the TOC is inserted in the [Markdown] document
78 | 1. Save the document and you are done
79 |
80 | Now you can go on and edit your document further or you can customize you TOC, please read on.
81 |
82 | ## Features
83 |
84 | The **MarkdownTOC** plugin is rich on features and customization, useful for both work on a single [Markdown] document or if you have several [Markdown] documents that require _special_ TOC generation.
85 |
86 | - [Insertion of TOC based on headings in Markdown document](#insertion-of-toc-based-on-headings-in-markdown-document)
87 | - [Automatic refresh of TOC when Markdown document is saved](#automatic-refresh-of-toc-when-markdown-document-is-saved)
88 | - [Customizing generation of TOC using attributes](#customizing-generation-of-toc-using-attributes)
89 | - [Auto anchoring when heading has anchor defined](#auto-anchoring-when-heading-has-anchor-defined)
90 | - [Auto linking for _clickable_ TOC](#auto-linking-for-clickable-toc)
91 | - [Lowercasing in ids](#lowercasing-in-ids)
92 | - [Preserve case](#preserve-case)
93 | - [Lowercase all characters](#lowercase-all-characters)
94 | - [Manipulation of auto link ids](#manipulation-of-auto-link-ids)
95 | - [URI encoding](#uri-encoding)
96 | - [Markdown Preview compatible](#markdown-preview-compatible)
97 | - [Link Prefix](#link-prefix)
98 | - [Control of levels listed in TOC](#control-of-levels-listed-in-toc)
99 | - [Ordered or unordered style for TOC elements](#ordered-or-unordered-style-for-toc-elements)
100 | - [Customizable list bullets in TOC](#customizable-list-bullets-in-toc)
101 | - [Specify custom indentation prefix](#specify-custom-indentation-prefix)
102 | - [Preserve images in headings](#preserve-images-in-headings)
103 | - [Excluded headings](#excluded-heading)
104 |
105 | ### Insertion of TOC based on headings in Markdown document
106 |
107 | When you have completed the [installation](#installation) of the plugin, you can insert an automatically generated TOC based on your [Markdown] headings. See the [Quick Start](#quick-start) to get going or the [Usage section](#usage) for details on how to utilize customization and [configuration](#configuration).
108 |
109 | For the following sample [Markdown] document:
110 |
111 | ```markdown
112 |
113 | # Heading 0
114 |
115 | Headings before MarkdownTOC tags will be ignored.
116 |
117 | ◀ place the cursor here and generate the TOC
118 |
119 | # Heading 1
120 | Lorem ipsum...
121 |
122 | ## Heading 2
123 | Lorem ipsum...
124 | ```
125 |
126 | The **MarkdownTOC** plugin will out of the box generate:
127 |
128 | ```markdown
129 | # Heading 0
130 |
131 | Headings before MarkdownTOC tags will be ignored.
132 |
133 |
134 |
135 | - Heading 1
136 | - Heading 2
137 |
138 |
139 |
140 | # Heading 1
141 | Lorem ipsum...
142 |
143 | ## Heading 2
144 | Lorem ipsum...
145 | ```
146 |
147 | As you can read from the sample above:
148 |
149 | 1. Headings above the `MarkdownTOC` tag section are ignored, only the rest of the document is considered _in scope_
150 |
151 | ### Automatic refresh of TOC when Markdown document is saved
152 |
153 | If we edit the [Markdown] document some more and add an additional heading:
154 |
155 | ```markdown
156 | ## Heading 3
157 | ```
158 |
159 | When we save the document, the TOC is automatically updated.
160 |
161 | ```markdown
162 |
163 |
164 | - Heading 1
165 | - Heading 2
166 | - Heading 3
167 |
168 |
169 |
170 | # Heading 1
171 | Lorem ipsum...
172 |
173 | ## Heading 2
174 | Lorem ipsum...
175 |
176 | ## Heading 3
177 | Lorem ipsum... (the added text)
178 | ```
179 |
180 | Same goes for deleted headings, these are cleared out.
181 |
182 | Updating the TOC can also be accomplished without saving by picking from the menu: Tools > MarkdownTOC > Update TOC
183 |
184 | #### Supported file extensions
185 |
186 | Make sure your file's extension is in the following list.
187 |
188 | `.md` `.markdown` `.mdown` `.mdwn` `.mkdn` `.mkd` `.mark`
189 |
190 | ### Customizing generation of TOC using attributes
191 |
192 | ```markdown
193 |
194 |
195 | - [Heading 1](#heading-1)
196 | - [Heading 2](#heading-2)
197 | - [Heading 3](#heading-3)
198 |
199 |
200 |
201 | # Heading 1
202 | Lorem ipsum...
203 |
204 | ## Heading 2
205 | Lorem ipsum...
206 |
207 | ## Heading 3
208 | Lorem ipsum... (the added text)
209 | ```
210 |
211 | 1. TOC tags can overwrite default [attributes](#Attributes) using local settings and influence the rendering of the TOC. See: [Configuration](#configuration) on how to set your own defaults for the plugin
212 | 1. Headings can be automatically linked (see: [auto link](#auto-link))
213 | 1. Headings can have anchors automatically linked (see: [Auto anchoring when heading has anchor defined](#auto-anchoring-when-heading-has-anchor-defined))
214 |
215 | The default behaviour could also be described as:
216 |
217 | ```markdown
218 |
219 | ```
220 |
221 | Please see: [Github Configuration](#github-configuration) for a guideline to configuring **MarkdownTOC** for [Github] use.
222 |
223 | ### Auto anchoring when heading has anchor defined
224 |
225 | You can add an HTML anchor (``) before your heading automatically.
226 |
227 | ```markdown
228 | # Heading with anchor [with-anchor]
229 | ```
230 |
231 | The TOC generation can be specified to respect this and a TOC element of the following format is generated:
232 |
233 | ```markdown
234 | - [Heading with anchor](#with-anchor)
235 | ```
236 |
237 | Please note that the default for the attribute: [autoanchor](#autoanchor) is `false`.You can add an HTML anchor (``) before the heading automatically.
238 |
239 | ```markdown
240 |
241 |
242 | - [Changelog](#changelog)
243 | - [Glossary](#glossary)
244 | - [API Specification](#api-specification)
245 |
246 |
247 |
248 |
249 | # Changelog
250 | Lorem ipsum...
251 |
252 |
253 | # Glossary
254 | Lorem ipsum...
255 |
256 |
257 | # API Specification
258 | Lorem ipsum...
259 | ```
260 |
261 | Please note that the default for autolink is `false` defined by the [attribute](#attributes) `defaults.autoanchor`. See also: [How to remove anchors added by MarkdownTOC](#how-to-remove-anchors-added-by-markdowntoc).
262 |
263 | ### Auto linking for _clickable_ TOC
264 |
265 | The plugin can be specified to auto link heading so you get a TOC with _clickable_ hyperlink elements.
266 |
267 | The following sample document:
268 |
269 | ```markdown
270 | # Heading 1
271 | Lorem ipsum...
272 |
273 | ## Heading 2
274 | Lorem ipsum...
275 |
276 | ## Heading 3
277 | Lorem ipsum...
278 | ```
279 |
280 | With `autolink` set to `true` will render the following:
281 |
282 | ```markdown
283 |
284 |
285 | - [Heading 1](#heading-1)
286 | - [Heading 2](#heading-2)
287 | - [Heading 3](#heading-3)
288 | - [Heading 4](#heading-4)
289 | - [Heading with anchor](#with-anchor)
290 |
291 |
292 | ```
293 |
294 | The auto link markup style can be one of:
295 |
296 | - `round`, the default, the style supported on [Github]
297 | - `square`, the ["Markdown standard reference-style links"][MarkdownLinks] style.
298 |
299 | Please note that the default for autolink is `false` defined by the [attribute](#attributes) `defaults.autolink`.
300 |
301 | ```markdown
302 |
303 |
304 | - MarkdownTOC Plugin for Sublime Text
305 | - Feature
306 | - Feature
307 | - Feature
308 |
309 |
310 | ```
311 | ```markdown
312 |
313 |
314 | - [MarkdownTOC Plugin for Sublime Text](#markdowntoc-plugin-for-sublime-text)
315 | - [Feature](#feature)
316 | - [Feature](#feature-1)
317 | - [Feature](#feature-2)
318 |
319 |
320 | ```
321 |
322 | **round**: according to [Github] style.
323 |
324 | ```markdown
325 |
326 |
327 | - [Heading](#heading)
328 |
329 |
330 | ```
331 |
332 | **square**: according to ["Markdown standard reference-style links"][MarkdownLinks].
333 |
334 | ```markdown
335 |
336 |
337 | - [Heading][heading]
338 |
339 |
340 | ```
341 |
342 | Please note that the default for bracket is `round` defined by the [attribute](#attributes) `defaults.bracket`.
343 |
344 | #### Lowercasing in ids
345 |
346 | By default the plugin lowercases ASCII based alphabets **only** (`a` to `z`) for auto links.
347 |
348 | ```markdown
349 |
350 |
351 | - [ПРИМЕР EXAMPLE][ПРИМЕР-example]
352 |
353 |
354 |
355 | # ПРИМЕР EXAMPLE
356 | ```
357 |
358 | This is same as setting `lowercase` attribute to `only_ascii`.
359 |
360 | ```markdown
361 |
362 |
363 | - [ПРИМЕР EXAMPLE][ПРИМЕР-example]
364 |
365 |
366 |
367 | # ПРИМЕР EXAMPLE
368 | ```
369 |
370 | ##### Preserve case
371 |
372 | You can disable the lowercasing capability by setting the `lowecase` attribute to `false`.
373 |
374 | ```markdown
375 |
376 |
377 | - [One Two Three][One-Two-Three]
378 |
379 |
380 |
381 | # One Two Three
382 | ```
383 |
384 | ##### Lowercase all characters
385 |
386 | Further more you can also expand the lowercasing capability by setting the `lowercase` attribute to `all`(or any values other than `false` and `only_ascii`).
387 |
388 | ```markdown
389 |
390 |
391 | - [ПРИМЕР EXAMPLE][пример-example]
392 |
393 |
394 |
395 | # ПРИМЕР EXAMPLE
396 | ```
397 |
398 | You can also specify this in your [configuration](#configuration) with key `defaults.lowercase`.
399 |
400 | #### Manipulation of auto link ids
401 |
402 | You can manipulate your link ids in your [configuration](#configuration) using the key `id_replacements`.
403 |
404 | ```json
405 | {
406 | "id_replacements": [
407 | {
408 | "pattern": "\\s+",
409 | "replacement": "-"
410 | },
411 | {
412 | "pattern": "!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|_|\\?|@|\\[|\\]|`|\"|\\.|<|>|{|}|™|®|©|<|>|&|'|"|<|>|&|'|"",
413 | "replacement": ""
414 | }
415 | ]
416 | }
417 | ```
418 |
419 | 1. Regular expression is allowed in each sets
420 | - It will be simply expanded into python's `re.sub(pattern, replacement, id)`
421 | 2. The replacement sequence executes from top to bottom
422 |
423 | An example:
424 |
425 | ```markdown
426 | # Super Product™
427 | ```
428 |
429 | This heading link of this heading is changed to following id
430 |
431 | ```markdown
432 | #super-product
433 | ```
434 |
435 | - The `' '` (space) is replaced with `-` (dash), since `' '` is included in the first set
436 | - The '™' is replaced with _nothing_, since '™' is included in the second set
437 |
438 | #### URI encoding
439 |
440 | By default non-ASCII characters in link ids are [URL encoded](https://en.wikipedia.org/wiki/Percent-encoding).
441 |
442 | ```markdown
443 |
444 |
445 | - [Ejemplos de español](#ejemplos-de-espa%C3%B1ol)
446 | - [日本語の例](#%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%81%AE%E4%BE%8B)
447 | - [Примеры русского](#%D0%9F%D1%80%D0%B8%D0%BC%D0%B5%D1%80%D1%8B-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%B3%D0%BE)
448 | - [中国的例子](#%E4%B8%AD%E5%9B%BD%E7%9A%84%E4%BE%8B%E5%AD%90)
449 |
450 |
451 |
452 | # Ejemplos de español
453 | # 日本語の例
454 | # Примеры русского
455 | # 中国的例子
456 | ```
457 |
458 | As mentioned you can disable this by setting the `uri_encoding` attribute to `false`, like so: `uri_encoding="false"`.
459 |
460 | ```markdown
461 |
462 |
463 | - [Ejemplos de español](#ejemplos-de-español)
464 | - [日本語の例](#日本語の例)
465 | - [Примеры русского](#Примеры-русского)
466 | - [中国的例子](#中国的例子)
467 |
468 |
469 |
470 | # Ejemplos de español
471 | # 日本語の例
472 | # Примеры русского
473 | # 中国的例子
474 | ```
475 |
476 | #### Markdown Preview compatible
477 |
478 | If you want to use **MarkdownTOC** with [Markdown Preview][MarkdownPreview], you should use `markdown_preview` attribute.
479 | You can set this attribute to either `markdown` or `github`.
480 |
481 | When you set it to `markdown`, you can get same links rendered by MarkdownPreview's markdown parser.
482 |
483 | ```markdown
484 |
485 |
486 | - [Hello 世界 World](#hello-world)
487 | - [ESPAÑA](#espana)
488 | - [ПРИМЕР RUSSIAN](#russian)
489 |
490 |
491 |
492 | # Hello 世界 World
493 | # ESPAÑA
494 | # ПРИМЕР RUSSIAN
495 | ```
496 |
497 | When you set it to `github`, you can get same links rendered by MarkdownPreview's github parser.
498 |
499 | ```markdown
500 |
501 |
502 | - [Hello 世界 World](#hello-%25E4%25B8%2596%25E7%2595%258C-world)
503 | - [ESPAÑA](#espa%25C3%25B1a)
504 | - [ПРИМЕР RUSSIAN](#%25D0%25BF%25D1%2580%25D0%25B8%25D0%25BC%25D0%25B5%25D1%2580-russian)
505 |
506 |
507 |
508 | # Hello 世界 World
509 | # ESPAÑA
510 | # ПРИМЕР RUSSIAN
511 | ```
512 |
513 | Currently no other parsers are supported.
514 |
515 | If you want to disable this feature, set it to `false`.
516 |
517 | #### Link Prefix
518 |
519 | You can also set _prefix_ of links.
520 |
521 | ```markdown
522 |
523 |
524 | - [My Heading](#user-content-my-heading)
525 |
526 |
527 |
528 | # My Heading
529 | ```
530 |
531 | You can manipulate this in your [configuration](#configuration) using the key `defaults.link_prefix`.
532 |
533 | ### Control of levels listed in TOC
534 |
535 | ```markdown
536 | # Heading 1
537 | Lorem ipsum...
538 |
539 | ## Heading 2
540 | Lorem ipsum...
541 |
542 | ### Heading 3
543 | Lorem ipsum...
544 |
545 | #### Heading 4
546 | Lorem ipsum...
547 | ```
548 |
549 | With default levels:
550 |
551 | ```markdown
552 |
553 |
554 | - Heading 1
555 | - Heading 2
556 | - Heading 3
557 | - Heading 4
558 |
559 |
560 | ```
561 |
562 | With levels set to 1,2:
563 |
564 | ```markdown
565 |
566 |
567 | - Heading 1
568 | - Heading 2
569 |
570 |
571 | ```
572 |
573 | Please note that the default for the [attribute](#attributes) levels is `"1,2,3,4,5,6"`, it means all heading sizes will be included.
574 |
575 | You can also specify this in your [configuration](#configuration) with key `defaults.levels`.
576 |
577 | The maximum size for headings is `6` according to the [Markdown specification][Markdown]
578 |
579 | ### Ordered or unordered style for TOC elements
580 |
581 | The plugin supports two styles of TOC element listing:
582 |
583 | - `unordered`
584 | - `ordered`
585 |
586 | A [Markdown] document with the following contents:
587 |
588 | ```markdown
589 | # Heading 1
590 | Lorem ipsum...
591 |
592 | ## Heading 2
593 | Lorem ipsum...
594 |
595 | ### Heading 3
596 | Lorem ipsum...
597 |
598 | ### Heading 4
599 | Lorem ipsum...
600 |
601 | ## Heading 5
602 | Lorem ipsum...
603 |
604 | # Heading 6
605 | Lorem ipsum...
606 | ```
607 |
608 | Will with style `unordered`:
609 |
610 | ```markdown
611 |
612 |
613 | - Heading 1
614 | - Heading 2
615 | - Heading 3
616 | - Heading 4
617 | - Heading 5
618 | - Heading 6
619 |
620 |
621 | ```
622 |
623 | And with style `ordered`:
624 |
625 | ```markdown
626 |
627 |
628 | 1. Heading 1
629 | 1. Heading 2
630 | 1. Heading 3
631 | 1. Heading 4
632 | 1. Heading 5
633 | 1. Heading 6
634 |
635 |
636 | ```
637 |
638 | Please note that the default for the [attribute](#attributes) is: `unordered`.
639 |
640 | You can set your default style in your [configuration](#configuration) with the key `defaults.style`.
641 |
642 | ### Customizable list bullets in TOC
643 |
644 | You can define the list items used for the TOC for each level. The first item is for the first level, the second for the second and so on until the last one of the list and then it starts over from the beginning.
645 |
646 | ```markdown
647 |
648 |
649 | - foo
650 | + bar
651 | * baz
652 | - foo
653 | + bar
654 | * baz
655 |
656 |
657 | ```
658 |
659 | You can set default list bullets in your [configuration](#configuration) with the key `defaults.bullets`.
660 |
661 | The example above could also be described as:
662 |
663 | ```json
664 | {
665 | "defaults": {
666 | "bullets": ["-","+","*"]
667 | }
668 | }
669 | ```
670 |
671 | You can also set it in attribute. In this case the values type is **'conmma separated string'**.
672 |
673 | ```markdown
674 |
675 | ```
676 |
677 | ### Specify custom indentation prefix
678 |
679 | The indentation prefix is a specification of the string used to indent the TOC elements.
680 |
681 | An _ugly_ but demonstrative example could be to use an [emoji][emoji].
682 |
683 | ```markdown
684 |
685 |
686 | - [Heading 1](#heading-1)
687 | :point_right: - [Heading 2](#heading-2)
688 | :point_right: :point_right: - [Heading 3](#heading-3)
689 | :point_right: :point_right: - [Heading 4](#heading-4)
690 | :point_right: - [Heading 5](#heading-5)
691 | - [Heading 6](#heading-6)
692 |
693 |
694 | ```
695 |
696 | Please note that the default for the [attribute](#attributes) is: `'\t'`.
697 |
698 | You can set your default indentation in your [configuration](#configuration) with the key `defaults.indent`.
699 |
700 | ### Preserve images in headings
701 |
702 | If you want to preserve images in headings, set `remove_image` to `false`.
703 |
704 | ```markdown
705 |
706 |
707 | -  Everything is OK
708 |
709 |
710 |
711 | #  Everything is OK
712 | ```
713 |
714 | Please note that the default for the [attribute](#attributes) is: `false`.
715 |
716 | ```markdown
717 |
718 |
719 | - Everything is OK
720 |
721 |
722 |
723 | #  Everything is OK
724 | ```
725 |
726 | You can change your default setting in your [configuration](#configuration) with the key `defaults.remove_image`.
727 |
728 | ### Excluded headings
729 |
730 | You can exclude certain headings in the TOC by adding a special comment to the line above the line with the heading, as shown below.
731 |
732 | ```markdown
733 |
734 | ## This heading will be excluded
735 | ```
736 |
737 | ## Usage
738 |
739 | 1. Open your [Markdown] file
740 | 2. Set cursor to position where you want to insert a TOC
741 | 3. Pick from menu: Tools > MarkdownTOC > Insert TOC
742 | 4. TOC is inserted in document
743 | 5. Evaluate your TOC and customize using [attributes](#attributes) or [configuration](#configuration)
744 | 6. Update contents and save...
745 | 7. TOC has been updated
746 |
747 | ***Don't remove the comment tags if you want to update every time saving.***
748 |
749 | ## Tips
750 |
751 | ### How to remove anchors added by MarkdownTOC
752 |
753 | If you want to remove the TOC again, you do not have to go through your complete Markdown and remove all tags manually - just follow this simple guide (see also: [Auto anchoring when heading has anchor defined](#auto-anchoring-when-heading-has-anchor-defined)).
754 |
755 | 1. Open your [Markdown] file
756 | 2. Set the attribute `autoanchor` to `false`, this clears all anchors
757 |
758 | ```markdown
759 |
760 | ```
761 |
762 | Please see the below animation demonstrating the change
763 |
764 | 
765 |
766 |
- Now delete the TOC section from beginning to end and **MarkdownTOC** integration is gone
767 |
768 | ```markdown
769 |
770 |
771 | ...
772 |
773 |
774 | ```
775 |
776 | Ref: [Github issue #76](https://github.com/naokazuterada/MarkdownTOC/issues/76)
777 |
778 | ### Addressing issues with Github Pages
779 |
780 | If you are using Github Pages you might experience that some themes do not render heading correctly.
781 |
782 | This can be addressed simply by setting `autoanchor` to `false`
783 |
784 | ```markdown
785 |
786 | ```
787 |
788 | And when **Jekyll** is done, your headings should render correctly.
789 |
790 | Ref: [Github issue #81](https://github.com/naokazuterada/MarkdownTOC/issues/81)
791 |
792 | ### Using MarkdownTOC with Markdownlint
793 |
794 | If you are using [Markdownlint](https://github.com/DavidAnson/markdownlint) (Node implementation), it will report several violations out of the box.
795 |
796 | The basic configuration you can use to address these looks like the following:
797 |
798 | ```json
799 | {
800 | "html": false,
801 | "blanks-around-headings": false,
802 | "ul-indent": {
803 | "indent": 4
804 | }
805 | }
806 | ```
807 |
808 | - `html` set to `false`, to allow use of HTML since **MarkdownTOC** relies on HTML tags to assist the Markdown
809 | - `blanks-around-headings` should be set to `false`, since anchors are places closed to the headings that are listed in the TOC
810 | - `ul-indent` should have it's parameter `indent` set to `4` to adhere with the default of `4` used by **MarkdownTOC**, whereas **Markdownlint** defaults to `2`
811 |
812 | If you have configured **MarkdownTOC** differently, you can adjust your **Markdownlint** configuration accordingly.
813 |
814 | Do note that this tip is based on the **Node** implementation, [available on GitHub](https://github.com/DavidAnson/markdownlint), which uses a project specific `.markdownlint.json` based configuration.
815 |
816 | ## Limitations
817 |
818 | **MarkdownTOC** does come with some limitations.
819 |
820 | For more information on compatibility, please see [the dedicated section](#compatibility).
821 |
822 | ### Headings in lists are not included in the auto-generated table of contents
823 |
824 | Example of [Markdown] heading in a [Markdown] listing, not being included in the auto-generated Table of Contents
825 |
826 | ```markdown
827 | - # this is a heading
828 | ```
829 |
830 | ## Attributes
831 |
832 | The following attributes can be used to control the generation of the TOC.
833 |
834 | | attribute | values | default |
835 | |:-----------------------|:------------------------------------------|:----------------|
836 | | `autoanchor` | `true`or`false` | `false` |
837 | | `autolink` | `true`or`false` | `false` |
838 | | `bracket` | `"round"`or`"square"` | `"round"` |
839 | | `indent` | string | `"\t"` |
840 | | `levels` | string (decimal list separated with `,`) | `"1,2,3,4,5,6"` |
841 | | `link_prefix` | string | `""` |
842 | | `bullets` | string | `"-"` |
843 | | `lowercase` | `"all"`or`"only_ascii"`or`"false"` | `"only_ascii"` |
844 | | `remove_image` | `true`or`false` | `true` |
845 | | `style` | `"ordered"` or `"unordered"` | `"unordered"` |
846 | | `uri_encoding` | `true`or`false` | `true` |
847 | | `markdown_preview` | `""`or`"github"`or`"markdown"` | `""` |
848 |
849 | You can define your own default values via package preferences, [Sublime Text][SublimeText]'s way of letting users customize [package settings][SublimeTextSettings]. Please see the [Section on Configuration](#Configuration) for more details for **MarkdownTOC**.
850 |
851 | ## Installation
852 |
853 | ### Using Package Control
854 |
855 | 1. Run “Package Control: Install Package” command, find and install `MarkdownTOC` plugin.
856 | 2. Restart [Sublime Text][SublimeText]
857 |
858 | > [Package Control][PackageControl]
859 |
860 | ### From Git
861 |
862 | ```sh
863 | git clone git@github.com:naokazuterada/MarkdownTOC.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/MarkdownTOC
864 | ```
865 |
866 | ### From downloadable archive
867 |
868 | 1. [Download zip-file](https://github.com/naokazuterada/MarkdownTOC/archive/master.zip) and unpack it.
869 | 2. Open the [Sublime Text][sublimetext] `Packages/` directory (pick menu: Sublime Text > Preferences > Browse Packages).
870 | 3. Move the `MarkdownTOC/` directory into the `Packages/` directory.
871 |
872 | ## Configuration
873 |
874 | You can use [attributes](#attributes) to customize a TOC in a single [Markdown] document, but if you want to keep the same TOC configuration accross multiple [Markdown] documents, you can configure your own defaults.
875 |
876 | Pick: `Sublime Text > Preferences > Package Settings > MarkdownTOC > Settings - User`
877 |
878 | Alternatively you can create the file `~/Library/Application Support/Sublime Text 3/Packages/User/MarkdownTOC.sublime-settings` by hand.
879 |
880 | Example: `MarkdownTOC.sublime-settings`
881 |
882 | ```json
883 | {
884 | "defaults": {
885 | "autolink": true,
886 | "bracket": "square",
887 | "levels": "1,2",
888 | "indent": " ",
889 | "remove_image": false,
890 | "bullets": "*",
891 | "style": "ordered"
892 | },
893 | "id_replacements": [
894 | {
895 | "pattern": "\\s+",
896 | "replacement": "-"
897 | },
898 | {
899 | "pattern": "<|>|&|'|"|<|>|&|'|"|!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|_|\\?|@|\\[|\\]|`|\"|\\.|<|>|{|}|™|®|©",
900 | "replacement": ""
901 | }
902 | ]
903 | }
904 | ```
905 |
906 | Please see the section on [attributes](#attributes) for an overview of values and the [section on customization](#customizing-generation-of-toc-using-attributes).
907 |
908 | Configuration precendence is as follows:
909 |
910 | 1. Attributes specified in **MarkdownTOC** begin tag (see: [Customizing generation of TOC using attributes](#customizing-generation-of-toc-using-attributes))
911 | 1. **MarkdownTOC** Settings - user (this section)
912 | 1. **MarkdownTOC** Settings - default (see: [Attributes](#attributes))
913 |
914 | For an overview of the specific behaviour behind an attribute, please refer to the below list.
915 |
916 | - `defaults.autolink`, (see: [Auto linking for _clickable_ TOC](#auto-linking-for-clickable-toc))
917 | - `defaults.autoanchor`, (see: [Auto anchoring when heading has anchor defined](#auto-anchoring-when-heading-has-anchor-defined))
918 | - `defaults.bracket`, (see: [Auto linking for _clickable_ TOC](#auto-linking-for-clickable-toc))
919 | - `defaults.indent`, (see: [Specify custom indentation prefix](#specify-custom-indentation-prefix))
920 | - `defaults.link_prefix`, (see: [Link Prefix](#link-prefix))
921 | - `defaults.levels`, (see: [Control of levels listed in TOC](#control-of-levels-listed-in-toc))
922 | - `defaults.bullets`, (see: [Customizable list bullets in TOC](#customizable-list-bullets-in-toc))
923 | - `defaults.lowercase`, (see: [Lowercasing in ids](#lowercasing-in-ids))
924 | - `defaults.remove_image`, (see: [Preserve images in headings](#maintain-the-images-in-headings))
925 | - `defaults.style`, (see: [Ordered or unordered style for TOC elements](#ordered-or-unordered-style-for-toc-elements))
926 | - `defaults.uri_encoding`, (see: [URI encoding](#uri-encoding))
927 | - `defaults.markdown_preview`, (see: [Markdown Preview compatible](#markdown-preview-compatible))
928 | - `id_replacements`, (see: [Manipulation of auto link ids](#manipulation-of-auto-link-ids))
929 |
930 | ### Github Configuration
931 |
932 | A configuration for writing Markdown primaily for use on [Github] _could_ look like the following:
933 |
934 | ```json
935 | {
936 | "defaults": {
937 | "autolink": true,
938 | "bracket": "round",
939 | "lowercase": "only_ascii"
940 | }
941 | }
942 | ```
943 |
944 | ### Configuration and Collaboration
945 |
946 | You should be aware that if you collaborate with other [Markdown] writers and users of **MarkdownTOC**, you might have changes going back and forth simply due to differing configurations.
947 |
948 | If that is the case and you cannot agree on a configuration, choose configuration using attributes specified in the document instead.
949 |
950 | Example of attribute configuration for the above configuration settings in file:
951 |
952 | ```markdown
953 |
954 | ```
955 |
956 | ## Compatibility
957 |
958 | This is by no means an exhaustive list and you are welcome to provide additional information and feedback. Here is listed what Markdown rendering platforms and tools where compatibility and incompatibily has been asserted with the **MarkdownTOC** plugin.
959 |
960 | | Application | Compatibility |
961 | | ------------ | ------------- |
962 | | [Github](https://github.com/) | Compatible |
963 | | [Gitblit](http://gitblit.com/) 1.6.x | Incompatible |
964 | | [Gitlab](https://about.gitlab.com/) 8.10.x | Compatible |
965 | | [BitBucket](https://bitbucket.org/) 5.12.2 | Incompatible |
966 |
967 | ## Contributing
968 |
969 | Contributions are most welcome, please see the [guidelines on contributing](https://github.com/naokazuterada/MarkdownTOC/blob/master/.github/CONTRIBUTING.md).
970 |
971 | ## License
972 |
973 | - **MarkdownTOC** is licensed under the [MIT License](https://github.com/naokazuterada/MarkdownTOC/blob/master/LICENSE-MIT)
974 |
975 | ## Author
976 |
977 | - [Naokazu Terada](https://github.com/naokazuterada)
978 |
979 | ## References
980 |
981 | - [Daring Fireballs Markdown Syntax Specification][Markdown]
982 | - [Sublime Text][SublimeText]
983 | - [Sublime Text: Package Control][PackageControl]
984 | - [Emoji cheatsheet][emoji]
985 | - [GitHub Flavored Markdown][Github]
986 | - [Markdown Preview][MarkdownPreview]
987 |
988 | ### Markdown Table of Contents Generators
989 |
990 | Here follows a list of other Markdown Table of Contents generators, for inspiration and perhaps even use in the situation where the **MarkdownTOC** Sublime Text plugin is _not the right tool for the job_. Please note that the list is by no means authoritative or exhaustive and is not a list of recommendations, since we can only endorse **MarkdownTOC** our contribution to the Markdown Table of Content generators toolbox.
991 |
992 | - [doctoc](https://github.com/thlorenz/doctoc) Node (npm) implementation with CLI interface
993 | - [markdown-toclify](https://github.com/rasbt/markdown-toclify) Python implementation with CLI interface
994 |
995 | ### Recommended plugins for use with MarkdownTOC
996 |
997 | - [Markdown Numbered Headers](https://packagecontrol.io/packages/Markdown%20Numbered%20Headers) Sublime Text 3 plugin for Markdown, auto insert/update/remove header numbers
998 |
999 | [Markdown]: http://daringfireball.net/projects/markdown/syntax
1000 | [MarkdownLinks]: http://daringfireball.net/projects/markdown/syntax#link
1001 | [SublimeText]: http://www.sublimetext.com/
1002 | [SublimeTextSettings]: https://docs.sublimetext.info/en/latest/customization/settings.html
1003 | [PackageControl]: http://wbond.net/sublime_packages/package_control
1004 | [emoji]: http://www.emoji-cheat-sheet.com/
1005 | [Github]: https://help.github.com/articles/basic-writing-and-formatting-syntax/
1006 | [MarkdownPreview]: https://packagecontrol.io/packages/Markdown%20Preview
1007 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # Your package name
2 | PACKAGE = "UnitTesting-example"
3 |
4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5 | VAGRANTFILE_API_VERSION = "2"
6 |
7 | $script = <