@datalackey/update-markdown-toc 1.2.1 → 1.3.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 +0 -5
- package/dist/cli/descriptor.d.ts +1 -2
- package/dist/cli/descriptor.js +3 -41
- package/dist/engine/generateToc.js +16 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -316,11 +316,6 @@ When such errors occur, the tool prints an error message and exits non-zero with
|
|
|
316
316
|
|
|
317
317
|
When combined with `--verbose`, skipped files (Markdown files without start/end region markers) are reported explicitly. For example:
|
|
318
318
|
|
|
319
|
-
```bash
|
|
320
|
-
update-markdown-toc --recursive docs/ --verbose
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
319
|
```bash
|
|
325
320
|
update-markdown-toc --recursive docs/ --verbose
|
|
326
321
|
```
|
package/dist/cli/descriptor.d.ts
CHANGED
package/dist/cli/descriptor.js
CHANGED
|
@@ -1,50 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const DEFAULT_LINK_TIMEOUT_MS = 3000;
|
|
1
|
+
import { runLinkValidation } from "@datalackey/tooling-core";
|
|
3
2
|
export const descriptor = {
|
|
4
3
|
name: "update-markdown-toc",
|
|
5
4
|
description: "Auto-generate Table of Contents for Markdown files",
|
|
6
|
-
options: [
|
|
7
|
-
{
|
|
8
|
-
flag: "--no-external-link-check",
|
|
9
|
-
description: "Skip external link validation in check mode",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
flag: "-n",
|
|
13
|
-
description: "Skip external link validation in check mode (short form)",
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
flag: "--link-timeout-ms",
|
|
17
|
-
description: "Timeout in milliseconds for external link requests (default: 3000)",
|
|
18
|
-
requiresValue: true,
|
|
19
|
-
valueName: "ms",
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
flag: "-l",
|
|
23
|
-
description: "Timeout in milliseconds for external link requests (short form)",
|
|
24
|
-
requiresValue: true,
|
|
25
|
-
valueName: "ms",
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
parseOptions(standard, passthrough) {
|
|
29
|
-
const noExternalCheck = parseBooleanOption("--no-external-link-check", passthrough) ||
|
|
30
|
-
parseBooleanOption("-n", passthrough);
|
|
31
|
-
const timeoutMs = parseNumberOption("--link-timeout-ms", passthrough) ??
|
|
32
|
-
parseNumberOption("-l", passthrough) ??
|
|
33
|
-
DEFAULT_LINK_TIMEOUT_MS;
|
|
34
|
-
return {
|
|
35
|
-
...standard,
|
|
36
|
-
validateExternalLinks: noExternalCheck ? false : true,
|
|
37
|
-
linkTimeoutMs: timeoutMs,
|
|
38
|
-
};
|
|
39
|
-
},
|
|
5
|
+
options: [],
|
|
40
6
|
async afterRun(files, config) {
|
|
41
7
|
if (config.runMode !== "check") {
|
|
42
8
|
return;
|
|
43
9
|
}
|
|
44
|
-
await runLinkValidation(files,
|
|
45
|
-
...config,
|
|
46
|
-
validateExternalLinks: config.validateExternalLinks,
|
|
47
|
-
linkTimeoutMs: config.linkTimeoutMs,
|
|
48
|
-
});
|
|
10
|
+
await runLinkValidation(files, config);
|
|
49
11
|
},
|
|
50
12
|
};
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import GithubSlugger from "github-slugger";
|
|
2
2
|
const START = "<!-- TOC:START -->";
|
|
3
3
|
const END = "<!-- TOC:END -->";
|
|
4
|
+
function stripFencedLines(lines) {
|
|
5
|
+
let inFence = false;
|
|
6
|
+
const result = [];
|
|
7
|
+
for (const line of lines) {
|
|
8
|
+
if (line.startsWith("```")) {
|
|
9
|
+
inFence = !inFence;
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (!inFence)
|
|
13
|
+
result.push(line);
|
|
14
|
+
}
|
|
15
|
+
if (inFence)
|
|
16
|
+
throw new Error("Unclosed code fence (```) in document");
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
4
19
|
function detectLineEnding(text) {
|
|
5
20
|
return text.includes("\r\n") ? "\r\n" : "\n";
|
|
6
21
|
}
|
|
@@ -22,7 +37,7 @@ export function generateTOC(content) {
|
|
|
22
37
|
const lines = contentWithoutTOC.split(lineEnding);
|
|
23
38
|
const headings = [];
|
|
24
39
|
const slugger = new GithubSlugger();
|
|
25
|
-
for (const line of lines) {
|
|
40
|
+
for (const line of stripFencedLines(lines)) {
|
|
26
41
|
const m = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
27
42
|
if (!m)
|
|
28
43
|
continue;
|
package/package.json
CHANGED