@datalackey/update-markdown-toc 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -15
- package/bin/update-markdown-toc.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# update-markdown-toc
|
|
2
2
|
|
|
3
|
+
<!-- TOC:START -->
|
|
3
4
|
- [update-markdown-toc](#update-markdown-toc)
|
|
4
5
|
- [Introduction](#introduction)
|
|
5
6
|
- [Installation](#installation)
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
- [Single-File Processing (Strict Mode)](#single-file-processing-strict-mode)
|
|
17
18
|
- [Recursive Folder Traversal (Lenient Mode)](#recursive-folder-traversal-lenient-mode)
|
|
18
19
|
- [Guidelines For Project Contributors](#guidelines-for-project-contributors)
|
|
20
|
+
<!-- TOC:END -->
|
|
19
21
|
|
|
20
22
|
## Introduction
|
|
21
23
|
|
|
@@ -23,7 +25,8 @@ A Node.js command-line **documentation helper** which automatically:
|
|
|
23
25
|
|
|
24
26
|
- generates Table of Contents (TOC) blocks for Markdown files
|
|
25
27
|
- operates on either a single file, or recursively finds all `*.md` files from a root path
|
|
26
|
-
- regenerates TOCs from headings,
|
|
28
|
+
- regenerates TOCs from headings, targeting only regions explicitly marked with [TOC markers](#toc-markers)
|
|
29
|
+
- avoids gratuitous reformatting or changes of any kind outside of regions marked by the aforementioned [TOC markers](#toc-markers)
|
|
27
30
|
- avoids updating files when the generated TOC is already correct
|
|
28
31
|
- provides a `--check` mode which flags Markdown files with stale TOCs (intended for CI)
|
|
29
32
|
|
|
@@ -102,24 +105,29 @@ Options:
|
|
|
102
105
|
|
|
103
106
|
## TOC Markers
|
|
104
107
|
|
|
105
|
-
The tool operates only on files containing **both** markers
|
|
108
|
+
The tool operates only on files containing **both** start and end markers,
|
|
109
|
+
as *almost* shown below. Don't use these markers exactly as written. Use brackets ('<' and '>'), and not
|
|
110
|
+
squiggley braces (i.e., not '{' and '}'). The reason for this documentation
|
|
111
|
+
oddity is that, if we used brackets,
|
|
112
|
+
then when we run our tool against this code base we would end up getting an unwanted table of contents below !
|
|
113
|
+
|
|
106
114
|
|
|
107
115
|
```md
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
{!-- TOC:START --}
|
|
117
|
+
{!-- TOC:END --}
|
|
110
118
|
```
|
|
111
119
|
|
|
112
|
-
Any existing content between
|
|
120
|
+
Any existing content between the region start and end markers is lost. The new content will be the generated TOC that
|
|
113
121
|
reflects the section headers marked with '#'s in the Markdown document.
|
|
114
122
|
|
|
115
123
|
Content outside the markers is preserved verbatim.
|
|
124
|
+
If either marker is missing, the tool prints an error message and exits with a non-zero status code.
|
|
116
125
|
|
|
117
126
|
|
|
118
127
|
## Usage Scenarios
|
|
119
128
|
|
|
120
129
|
|
|
121
130
|
|
|
122
|
-
|
|
123
131
|
### As Part of code/test/debug Work Flow
|
|
124
132
|
|
|
125
133
|
To ensure that your code is built afresh, passes tests, and that your documentation TOCs are up to date, you could
|
|
@@ -143,9 +151,9 @@ Your `package.json` might look like this:
|
|
|
143
151
|
}
|
|
144
152
|
```
|
|
145
153
|
|
|
146
|
-
### Continuous Integration
|
|
154
|
+
### Continuous Integration
|
|
147
155
|
|
|
148
|
-
The --check flag is designed primarily for continuous integration.
|
|
156
|
+
The --check flag is designed primarily for continuous integration (CI).
|
|
149
157
|
|
|
150
158
|
In this mode, the tool:
|
|
151
159
|
|
|
@@ -175,14 +183,21 @@ In the case of the latter mode, we assume some files may not yet have TOC marker
|
|
|
175
183
|
|
|
176
184
|
#### Single-File Processing (Strict Mode)
|
|
177
185
|
|
|
178
|
-
When a single Markdown file is explicitly specified (or when the default README.md is used), the tool operates in strict mode.
|
|
179
186
|
|
|
180
|
-
|
|
187
|
+
When a single Markdown file is explicitly specified (or when the default README.md is used),
|
|
188
|
+
the tool operates in strict mode.
|
|
189
|
+
In this mode, any of the following conditions cause an immediate error and a non-zero exit code:
|
|
190
|
+
|
|
191
|
+
- file does not exist, or cannot be read (e.g. due to permissions).
|
|
192
|
+
- file does not contain both TOC delimiters (<!-- TOC:START --> and <!-- TOC:END -->).
|
|
193
|
+
- file is stale (i.e. the existing TOC differs from the generated TOC).
|
|
194
|
+
- file contains TOC delimiters but no Markdown headings are found from which a TOC can be generated.
|
|
195
|
+
|
|
196
|
+
|
|
181
197
|
|
|
182
|
-
The file must contain both TOC markers:
|
|
183
198
|
```md
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
{!-- TOC:START --}
|
|
200
|
+
{!-- TOC:END --}
|
|
186
201
|
|
|
187
202
|
```
|
|
188
203
|
|
|
@@ -193,12 +208,19 @@ If either marker is missing, the tool prints an error message and exits with a n
|
|
|
193
208
|
|
|
194
209
|
When operating in recursive mode, the tool traverses a directory tree and processes all *.md files it finds.
|
|
195
210
|
In this mode, files without TOC markers are silently skipped, and files with TOC markers are processed normally.
|
|
211
|
+
(Rational: for larger repos, it may not be feasible to add TOC markers to every Markdown file at once.)
|
|
212
|
+
Stale files are reported (unless --quiet is specified) and will
|
|
213
|
+
result in a non-zero return value at the end of processing, but the
|
|
214
|
+
script will not immediately bail wiht an error -- processing continues for all files found.
|
|
196
215
|
|
|
197
|
-
When combined with --verbose, skipped files
|
|
216
|
+
When combined with --verbose, skipped files (Markdown files without start/end region markers)
|
|
217
|
+
are reported explicitly in this mode. For example:
|
|
198
218
|
|
|
219
|
+
```bash
|
|
199
220
|
update-markdown-toc --recursive docs/ --verbose
|
|
221
|
+
```
|
|
200
222
|
|
|
201
|
-
|
|
223
|
+
yields example output:
|
|
202
224
|
|
|
203
225
|
```
|
|
204
226
|
Skipped (no markers): docs/legacy-notes.md
|
|
File without changes
|
package/package.json
CHANGED