markdown_link_checker_sc 0.0.138 → 0.0.140
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 +21 -10
- package/index.js +36 -7
- package/package.json +1 -1
- package/px4_link_errors - Copy.txt +1282 -0
- package/px4_link_errors.txt +1282 -0
- package/src/errors.js +40 -0
- package/src/filters.js +16 -0
- package/src/process_external_url_links.js +561 -0
- package/tests/testDictionary.json +18123 -0
- package/tests/testDictionaryOrig.json +304912 -0
- package/tests/test_ext_linkcheck.js +413 -0
package/README.md
CHANGED
|
@@ -13,21 +13,27 @@ Usage: markdown_link_checker_sc [options]
|
|
|
13
13
|
|
|
14
14
|
Options:
|
|
15
15
|
-r, --repo <path> Repo root directory. Defaults to current directory. Everything resolved relative to this.) (default: "")
|
|
16
|
-
-d, --doc [directory] Docs root directory, relative to -
|
|
16
|
+
-d, --doc [directory] Docs root directory, relative to -r (such as `docs`). Defaults to '' (all docs in root of repo). Use -d as well to restrict
|
|
17
|
+
search to a particular subfolder. Defaults to current directory. (default:
|
|
17
18
|
"D:\\github\\hamishwillee\\markdown_link_checker_sc")
|
|
18
|
-
-e, --subdir [directory] A subfolder of the docs root (-d) to search for markdown and html files. Such as: `en` for an English subfolder. Default
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
19
|
+
-e, --subdir [directory] A subfolder of the docs root (-d) to search for markdown and html files. Such as: `en` for an English subfolder. Default
|
|
20
|
+
empty (same as -d directory) (default: "")
|
|
21
|
+
-i, --imagedir [directory] The directory to search for all image files for global orphan checking, relative docs root (-d) - such as: `assets` or `en`.
|
|
22
|
+
Default empty if not explicitly set, and global orphan checking will not be done (default: "")
|
|
23
|
+
-c, --headingAnchorSlugify [value] Slugify approach for turning markdown headings into heading anchors. Currently support vuepress only and always (default:
|
|
24
|
+
"vuepress")
|
|
25
|
+
-h, --tryMarkdownforHTML [value] Try a markdown file extension check if a link to HTML fails. (default: true)
|
|
23
26
|
-l, --log <types...> Types of console logs to display logs for debugging. Types: functions, todo etc.
|
|
24
|
-
-f, --files <path> JSON file with array of files to report on (default is all files). JSON paths are usually relative to git repo root `-r`.
|
|
25
|
-
|
|
27
|
+
-f, --files <path> JSON file with array of files to report on (default is all files). JSON paths are usually relative to git repo root `-r`.
|
|
28
|
+
(default: "")
|
|
29
|
+
-t, --toc [value] full filename of TOC/Summary file in file system. If not specified, inferred from file with most links to other files
|
|
26
30
|
-u, --site_url [value] Site base url in form dev.example.com (used to catch absolute urls to local files)
|
|
27
31
|
-o, --logtofile [value] Output logs to file (default: true)
|
|
28
32
|
-p, --interactive [value] Interactively add errors to the ignore list at <repo>/_link_checker_sc/ignore_errors.json (default: false)
|
|
29
33
|
-c, --anchor_in_heading [value] Detect anchors in heading such as: # Heading {#anchor} (default: true)
|
|
30
|
-
-
|
|
34
|
+
-x, --externallink [value] Output logs to file (default: false)
|
|
35
|
+
-e, --errors [values] WIP (don't use) Error type names to remove, space separated. By default ExternalLinkWarning (default: "ExternalLinkWarning")
|
|
36
|
+
--help display help for command
|
|
31
37
|
```
|
|
32
38
|
|
|
33
39
|
## Ignore file
|
|
@@ -81,7 +87,7 @@ This does catch a LOT of cases though, and is pretty quick.
|
|
|
81
87
|
- Catches markdown files that are orphans - i.e. not linked by any file, or not linked by file which has the most links (normally the TOC file)
|
|
82
88
|
- Catches orphan images
|
|
83
89
|
- Allows you to specify that some errors are OK to ignore. These are stored in a file. See `-i` options\
|
|
84
|
-
|
|
90
|
+
- Can run its own external link checker if -x is True. This is quite useful as you can control what errors get reported.
|
|
85
91
|
|
|
86
92
|
## TODO
|
|
87
93
|
|
|
@@ -111,3 +117,8 @@ The way this works:
|
|
|
111
117
|
- Finally the output is exported in a markdown friendly output format.
|
|
112
118
|
|
|
113
119
|
Lots more to do, but this already catches lots of internal errors.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
<!-- Tests
|
|
124
|
+
node index.js -r D:\github\px4\PX4-Autopilot -d docs -e en -i assets -x True > px4_link_errors.txt -->
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { processMarkdown } from "./src/process_markdown.js";
|
|
|
19
19
|
import { processRelativeLinks } from "./src/process_relative_links.js";
|
|
20
20
|
import { checkLocalImageLinks } from "./src/process_local_image_links.js";
|
|
21
21
|
import { processUrlsToLocalSource } from "./src/process_internal_url_links.js";
|
|
22
|
+
import { processExternalUrlLinks } from "./src/process_external_url_links.js";
|
|
22
23
|
import {
|
|
23
24
|
checkPageOrphans,
|
|
24
25
|
getPageWithMostLinks,
|
|
@@ -34,7 +35,7 @@ program
|
|
|
34
35
|
)
|
|
35
36
|
.option(
|
|
36
37
|
"-d, --doc [directory]",
|
|
37
|
-
"Docs root directory, relative to -
|
|
38
|
+
"Docs root directory, relative to -r (such as `docs`). Defaults to '' (all docs in root of repo). Use -d as well to restrict search to a particular subfolder. Defaults to current directory.",
|
|
38
39
|
process.cwd()
|
|
39
40
|
)
|
|
40
41
|
.option(
|
|
@@ -53,7 +54,7 @@ program
|
|
|
53
54
|
"vuepress"
|
|
54
55
|
)
|
|
55
56
|
.option(
|
|
56
|
-
"-
|
|
57
|
+
"-h, --tryMarkdownforHTML [value]",
|
|
57
58
|
"Try a markdown file extension check if a link to HTML fails.",
|
|
58
59
|
true
|
|
59
60
|
)
|
|
@@ -67,7 +68,7 @@ program
|
|
|
67
68
|
""
|
|
68
69
|
)
|
|
69
70
|
.option(
|
|
70
|
-
"-
|
|
71
|
+
"-t, --toc [value]",
|
|
71
72
|
"full filename of TOC/Summary file in file system. If not specified, inferred from file with most links to other files"
|
|
72
73
|
)
|
|
73
74
|
.option(
|
|
@@ -86,6 +87,12 @@ program
|
|
|
86
87
|
"Detect anchors in heading such as: # Heading {#anchor}",
|
|
87
88
|
true
|
|
88
89
|
)
|
|
90
|
+
.option("-x, --externallink [value]", "Output logs to file", false)
|
|
91
|
+
.option(
|
|
92
|
+
"-e, --errors [values]",
|
|
93
|
+
"WIP (don't use) Error type names to remove, space separated. By default ExternalLinkWarning",
|
|
94
|
+
"ExternalLinkWarning"
|
|
95
|
+
)
|
|
89
96
|
.parse(process.argv);
|
|
90
97
|
|
|
91
98
|
// TODO PX4 special parsing - errors or pages we exclude by default.
|
|
@@ -130,6 +137,7 @@ sharedData.options.markdownroot = path.join(
|
|
|
130
137
|
//console.log(`debug: sharedData.options.subdir: ${sharedData.options.subdir}`);
|
|
131
138
|
//console.log(`debug: sharedData.options.docsroot: ${sharedData.options.docsroot}`);
|
|
132
139
|
//console.log(`debug: sharedData.options.markdownroot: ${sharedData.options.markdownroot}`);
|
|
140
|
+
//console.log(`debug: sharedData.options.errors: ${sharedData.options.errors}`);
|
|
133
141
|
|
|
134
142
|
//process.exit(1);
|
|
135
143
|
|
|
@@ -281,7 +289,7 @@ const processDirectory = async (dir) => {
|
|
|
281
289
|
pathToJsonIgnoreFile
|
|
282
290
|
);
|
|
283
291
|
|
|
284
|
-
// process
|
|
292
|
+
// process containing markdown, return results which includes links, headings, id anchors
|
|
285
293
|
const results = await processDirectory(sharedData.options.markdownroot);
|
|
286
294
|
|
|
287
295
|
if (!results.allErrors) {
|
|
@@ -325,6 +333,13 @@ const processDirectory = async (dir) => {
|
|
|
325
333
|
const errorsGlobalImageOrphanCheck = await checkImageOrphansGlobal(results);
|
|
326
334
|
results["allErrors"].push(...errorsGlobalImageOrphanCheck);
|
|
327
335
|
|
|
336
|
+
// Process links to externalURLs.
|
|
337
|
+
if (sharedData.options.externallink) {
|
|
338
|
+
const errorsFromExternalUrlLinks = await processExternalUrlLinks(results);
|
|
339
|
+
//console.log( `debug: errorsFromExternalUrlLinks: ${errorsFromExternalUrlLinks}` );
|
|
340
|
+
results["allErrors"].push(...errorsFromExternalUrlLinks);
|
|
341
|
+
}
|
|
342
|
+
|
|
328
343
|
// Filter the errors based on the settings in options.
|
|
329
344
|
// At time of writing just filters on specific set of pages.
|
|
330
345
|
let filteredResults = filterErrors(results.allErrors);
|
|
@@ -335,7 +350,21 @@ const processDirectory = async (dir) => {
|
|
|
335
350
|
outputErrors(filteredResults);
|
|
336
351
|
|
|
337
352
|
//make array and document options? ie. if includes ...
|
|
338
|
-
|
|
353
|
+
function censorCircular(key, value) {
|
|
354
|
+
if (typeof value === "object" && value !== null) {
|
|
355
|
+
// Check if this object has already been seen (is part of a cycle)
|
|
356
|
+
// A more robust solution might involve a WeakSet to track seen objects
|
|
357
|
+
// For simplicity here, we're just checking for the specific problematic property
|
|
358
|
+
if (key === "issuerCertificate") {
|
|
359
|
+
console.warn(`Circular reference detected in key: ${key}`);
|
|
360
|
+
return "[Circular]"; // Or undefined to omit it entirely
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const jsonFilteredErrors = JSON.stringify(filteredResults, censorCircular, 2);
|
|
367
|
+
//const jsonFilteredErrors = JSON.stringify(filteredResults, null, 2);
|
|
339
368
|
logToFile("./logs/filteredErrors.json", jsonFilteredErrors);
|
|
340
369
|
|
|
341
370
|
// Log filtered errors to standard out
|
|
@@ -344,14 +373,14 @@ const processDirectory = async (dir) => {
|
|
|
344
373
|
}
|
|
345
374
|
|
|
346
375
|
//make array and document options? ie. if includes ...
|
|
347
|
-
const jsonAllResults = JSON.stringify(results,
|
|
376
|
+
const jsonAllResults = JSON.stringify(results, censorCircular, 2);
|
|
348
377
|
logToFile("./logs/allResults.json", jsonAllResults);
|
|
349
378
|
if (sharedData.options.log.includes("allresults")) {
|
|
350
379
|
console.log(jsonAllResults);
|
|
351
380
|
}
|
|
352
381
|
|
|
353
382
|
//make array and document options? ie. if includes ...
|
|
354
|
-
const jsonAllErrors = JSON.stringify(results.allErrors,
|
|
383
|
+
const jsonAllErrors = JSON.stringify(results.allErrors, censorCircular, 2);
|
|
355
384
|
logToFile("./logs/allErrors.json", jsonAllErrors);
|
|
356
385
|
|
|
357
386
|
if (sharedData.options.log.includes("allerrors")) {
|