markdown_link_checker_sc 0.0.9 → 0.0.11

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.
Files changed (3) hide show
  1. package/README.md +29 -4
  2. package/index.js +7 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # markdown link checker sc
2
2
 
3
3
  ALPHA - Mostly just attempting better handling of internal links.
4
+ Probably never coming out of alpha. Bit of fun.
4
5
 
5
6
  Markdown link checker in node.
6
7
  Better handling of internal link checking.
@@ -9,10 +10,34 @@ Better handling of internal link checking.
9
10
  Current version only does internal link checking
10
11
 
11
12
  ```
12
- Usage: index [options]
13
+ Usage: markdown_link_checker_sc [options]
13
14
 
14
15
  Options:
15
- -d, --directory [directory] The directory to search for markdown and html files (default: is current directory)
16
- -h, --headingAnchorSlugify [value] Slugify approach for turning markdown headings into heading anchors. Currently support vuepress only and always (default: "vuepress")
17
- --help display help for command
16
+ -d, --directory [directory] The directory to search for markdown and html files (default:
17
+ "D:\\github\\hamishwillee\\markdown_link_checker_sc")
18
+ -s, --headingAnchorSlugify [value] Slugify approach for turning markdown headings into heading anchors. Currently
19
+ support vuepress only and always (default: "vuepress")
20
+ -t, --tryMarkdownforHTML [value] Try a markdown file extension check if a link to HTML fails. (default: true)
21
+ -l, --log [value] Export some logs for debugging. (default: false)
22
+ -f, --files <path> JSON file with array of files to report on (default is all files). Paths are
23
+ relative relative to -d by default, but -r can be used to set a different root.
24
+ (default: "")
25
+ -r, --root <path> Directory to prepend before file paths in the JSON directory. Default is same as
26
+ directory. Useful if directory is not your repo root (default: "")
27
+ -h, --help display help for command
18
28
  ```
29
+
30
+
31
+ The way this works:
32
+ - Sspecify the directory and it will search below that for all markdown/html files.
33
+ - It loads each file, and:
34
+ - parses for markdown and html style links for both page and image links.
35
+ - parses headings and builds list of anchors in the page (as per vuepress) for those headings (poorly tested code)
36
+ - parses for html elements with ids, that are also link targets.
37
+ - Then it parses the results, comparing internal links to internal anchors to see if it can find matching files, and matching headings or anchors within files.
38
+ - If it can't match, that is an error - which gets added to the list of errors with a type and enough detail to handle.
39
+ - Errors are then filtered based on:
40
+ - pages in a json file defined using -f (and possibly -r).
41
+ - Finally the output is exported in a markdown friendly output format.
42
+
43
+ Lots more to do, but this already catches lots of internal errors.
package/index.js CHANGED
@@ -11,7 +11,7 @@ program
11
11
  process.cwd()
12
12
  )
13
13
  .option(
14
- "-h, --headingAnchorSlugify [value]",
14
+ "-s, --headingAnchorSlugify [value]",
15
15
  "Slugify approach for turning markdown headings into heading anchors. Currently support vuepress only and always",
16
16
  "vuepress"
17
17
  )
@@ -402,7 +402,7 @@ function filterErrors(errors) {
402
402
  // This method filters all errors against settings in the command line - such as pages to output.
403
403
  let filteredErrors = errors;
404
404
  // Filter results on specified file names (if any specified)
405
- console.log(`Number pages to filter: ${options.files.length}`);
405
+ //console.log(`Number pages to filter: ${options.files.length}`);
406
406
  if (options.files.length > 0) {
407
407
  filteredErrors = errors.filter((error) => {
408
408
  //console.log(`Error: ${error}`);
@@ -449,17 +449,17 @@ function outputErrors(results) {
449
449
 
450
450
  //console.log(sortedByPageErrors);
451
451
  for (page in sortedByPageErrors) {
452
- console.log(`${page}`);
452
+ console.log(`\n${page}`);
453
453
  for (const error of sortedByPageErrors[page]) {
454
454
  if (error.type == "InternalLinkMissingFile") {
455
- console.log(` ${error.type}: ${error.linkUrl}`);
455
+ console.log(`- ${error.type}: ${error.linkUrl}`);
456
456
  //console.log(` ${error.type}: ${error.linkAnchor}, linkURL: ${error.linkUrl}`);
457
457
  // { "type": "InternalLinkMissingFile", "page": `${page.page_file}`, "linkUrl": `${link.linkUrl}`, "linkText": `${link.linkText}`, "linkUrlFilePath": `${linkAbsoluteFilePath}` };
458
458
  } else if (error.type == "InternalLocalMissingAnchor") {
459
459
  // missing anchor in linked file that exists.
460
460
  //console.log(error);
461
461
  console.log(
462
- ` ${error.type}: #${error.linkAnchor} (not found in current file)`
462
+ `- ${error.type}: #${error.linkAnchor} (not found in current file)`
463
463
  );
464
464
  //console.log(` ${error.type}: #${error.linkAnchor} (heading/anchor missing?)`);
465
465
  //console.log(` #${error.linkAnchor} - Internal anchor not found`);
@@ -470,7 +470,7 @@ function outputErrors(results) {
470
470
  // missing anchor in linked file that exists.
471
471
  //console.log(error);
472
472
  console.log(
473
- ` ${error.type}: #${error.linkAnchor} not found in ${error.linkUrlFilePath}`
473
+ `- ${error.type}: #${error.linkAnchor} not found in ${error.linkUrlFilePath}`
474
474
  );
475
475
  //console.log(` ${error.type}: #${error.linkAnchor} (heading/anchor missing?)`);
476
476
  //console.log(` #${error.linkAnchor} - Internal anchor not found`);
@@ -478,7 +478,7 @@ function outputErrors(results) {
478
478
  //console.log(` Internal anchor not found: #${error.linkAnchor} `);
479
479
  // { "type": "InternalMissingAnchor", "page": `${page.page_file}`, "linkAnchor": `${link.linkAnchor}`, "linkUrl": `${link.linkUrl}`, "linktext": `${link.linkText}`, "linkUrlFilePath": `${linkAbsoluteFilePath}` };
480
480
  } else if (error.type == "InternalLinkToHTML") {
481
- console.log(` ${error.type}: ${error.linkUrl} (should be ".md"?)`);
481
+ console.log(`- ${error.type}: ${error.linkUrl} (should be ".md"?)`);
482
482
  //console.log(` ${error.type}: linkURL: ${error.linkUrl} ends in ".html"`);
483
483
  // { "type": "InternalLinkToHTML", "page": `${page.page_file}`, "linkUrl": `${link.linkUrl}`, "linkText": `${link.linkText}`, "linkUrlFilePath": `${linkAbsoluteFilePath}` };
484
484
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown_link_checker_sc",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Markdown Link Checker",
5
5
  "main": "index.js",
6
6
  "scripts": {