@datalackey/update-markdown-toc 0.1.3 → 1.0.1
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 +48 -32
- package/bin/update-markdown-toc.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# update-markdown-toc
|
|
2
2
|
|
|
3
|
+
<!-- TOC:START -->
|
|
3
4
|
- [update-markdown-toc](#update-markdown-toc)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [Installation](#installation)
|
|
7
|
+
- [Usage](#usage)
|
|
8
|
+
- [Using npx (recommended)](#using-npx-recommended)
|
|
9
|
+
- [Using npm scripts](#using-npm-scripts)
|
|
10
|
+
- [Using a direct path (advanced)](#using-a-direct-path-advanced)
|
|
11
|
+
- [Options](#options)
|
|
12
|
+
- [TOC Markers](#toc-markers)
|
|
13
|
+
- [Usage Scenarios](#usage-scenarios)
|
|
14
|
+
- [As Part of code/test/debug Work Flow](#as-part-of-codetestdebug-work-flow)
|
|
15
|
+
- [Continuous Integration](#continuous-integration)
|
|
16
|
+
- [Recursively Traversing a Folder Hierarchy to Process all files vs. Single File Processing](#recursively-traversing-a-folder-hierarchy-to-process-all-files-vs-single-file-processing)
|
|
17
|
+
- [Single-File Processing (Strict Mode)](#single-file-processing-strict-mode)
|
|
18
|
+
- [Recursive Folder Traversal (Lenient Mode)](#recursive-folder-traversal-lenient-mode)
|
|
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,16 +183,17 @@ 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:
|
|
181
190
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
(See [TOC markers](#toc-markers) section about how we describe markers in this guide.)
|
|
194
|
+
- file is stale (i.e. the existing TOC differs from the generated TOC).
|
|
195
|
+
- file contains TOC delimiters but no Markdown headings are found from which a TOC can be generated.
|
|
186
196
|
|
|
187
|
-
```
|
|
188
197
|
|
|
189
198
|
If either marker is missing, the tool prints an error message and exits with a non-zero status code.
|
|
190
199
|
|
|
@@ -193,12 +202,19 @@ If either marker is missing, the tool prints an error message and exits with a n
|
|
|
193
202
|
|
|
194
203
|
When operating in recursive mode, the tool traverses a directory tree and processes all *.md files it finds.
|
|
195
204
|
In this mode, files without TOC markers are silently skipped, and files with TOC markers are processed normally.
|
|
205
|
+
(Rational: for larger repos, it may not be feasible to add TOC markers to every Markdown file at once.)
|
|
206
|
+
Stale files are reported (unless --quiet is specified) and will
|
|
207
|
+
result in a non-zero return value at the end of processing, but the
|
|
208
|
+
script will not immediately bail wiht an error -- processing continues for all files found.
|
|
196
209
|
|
|
197
|
-
When combined with --verbose, skipped files
|
|
210
|
+
When combined with --verbose, skipped files (Markdown files without start/end region markers)
|
|
211
|
+
are reported explicitly in this mode. For example:
|
|
198
212
|
|
|
213
|
+
```bash
|
|
199
214
|
update-markdown-toc --recursive docs/ --verbose
|
|
215
|
+
```
|
|
200
216
|
|
|
201
|
-
|
|
217
|
+
yields example output:
|
|
202
218
|
|
|
203
219
|
```
|
|
204
220
|
Skipped (no markers): docs/legacy-notes.md
|
|
File without changes
|
package/package.json
CHANGED