hdoc-tools 0.25.0 → 0.25.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/hdoc-validate.js +27 -23
- package/package.json +1 -1
package/hdoc-validate.js
CHANGED
@@ -53,7 +53,8 @@ const e = require("express");
|
|
53
53
|
"",
|
54
54
|
);
|
55
55
|
|
56
|
-
const
|
56
|
+
const markdown_paths = getMDPathFromHtmlPath(sourceFile);
|
57
|
+
|
57
58
|
const translate_output = translator.translate(text, spellcheck_options);
|
58
59
|
if (Object.keys(translate_output).length) {
|
59
60
|
for (const key in translate_output) {
|
@@ -68,9 +69,9 @@ const e = require("express");
|
|
68
69
|
) {
|
69
70
|
const link_location = hdoc.find_string_in_string(text.split('\n')[key - 1], spelling);
|
70
71
|
if (link_location !== null)
|
71
|
-
error_message = `${
|
72
|
+
error_message = `${markdown_paths.relativePath}:${key}:${link_location.column} - ${error_message}`;
|
72
73
|
else
|
73
|
-
error_message = `${
|
74
|
+
error_message = `${markdown_paths.relativePath}:${key} - ${error_message}`;
|
74
75
|
if (!excludes[source_path]) {
|
75
76
|
errors[sourceFile.relativePath].push(
|
76
77
|
`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`,
|
@@ -433,17 +434,20 @@ const e = require("express");
|
|
433
434
|
};
|
434
435
|
|
435
436
|
const getMDPathFromHtmlPath = (htmlFile) => {
|
436
|
-
const
|
437
|
-
|
437
|
+
const returnPaths = {
|
438
|
+
markdownPath: htmlFile.path.replace(`.${htmlFile.extension}`, '.md'),
|
439
|
+
relativePath: htmlFile.relativePath.replace(`.${htmlFile.extension}`, '.md')
|
440
|
+
};
|
441
|
+
if (!fs.existsSync(returnPaths.markdownPath)) {
|
438
442
|
// No matching markdown
|
439
|
-
|
443
|
+
returnPaths.markdownPath = htmlFile.path;
|
440
444
|
}
|
441
|
-
return
|
445
|
+
return returnPaths;
|
442
446
|
}
|
443
447
|
|
444
448
|
const checkLinks = async (source_path, htmlFile, links, hdocbook_config) => {
|
445
|
-
const
|
446
|
-
const markdown_content = fs.readFileSync(
|
449
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
450
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
447
451
|
|
448
452
|
for (let i = 0; i < links.length; i++) {
|
449
453
|
// Validate that link is a valid URL first
|
@@ -465,7 +469,7 @@ const e = require("express");
|
|
465
469
|
//Flat Anchor - validate we have a same-file hit
|
466
470
|
isHashAnchor(htmlFile, links[i]);
|
467
471
|
} else {
|
468
|
-
const error_message = processErrorMessage(`Root relative links should start with a forward-slash: ${links[i]}`,
|
472
|
+
const error_message = processErrorMessage(`Root relative links should start with a forward-slash: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
469
473
|
errors[htmlFile.relativePath].push(error_message);
|
470
474
|
}
|
471
475
|
} else {
|
@@ -505,7 +509,7 @@ const e = require("express");
|
|
505
509
|
links[i].toLowerCase().includes("docs.hornbill.com") ||
|
506
510
|
links[i].toLowerCase().includes("docs-internal.hornbill.com")
|
507
511
|
) {
|
508
|
-
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`,
|
512
|
+
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
509
513
|
errors[htmlFile.relativePath].push( error_message );
|
510
514
|
continue;
|
511
515
|
}
|
@@ -524,7 +528,7 @@ const e = require("express");
|
|
524
528
|
`Link is a valid external URL: ${links[i]}`,
|
525
529
|
);
|
526
530
|
} catch (e) {
|
527
|
-
const error_message = processErrorMessage(`Issue with external link: ${e} - ${links[i]}`,
|
531
|
+
const error_message = processErrorMessage(`Issue with external link: ${e} - ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
528
532
|
errors[htmlFile.relativePath].push(error_message);
|
529
533
|
}
|
530
534
|
}
|
@@ -532,13 +536,13 @@ const e = require("express");
|
|
532
536
|
};
|
533
537
|
|
534
538
|
const checkImages = async (source_path, htmlFile, links) => {
|
535
|
-
const
|
536
|
-
const markdown_content = fs.readFileSync(
|
539
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
540
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
537
541
|
for (let i = 0; i < links.length; i++) {
|
538
542
|
// Validate that image is a valid URL first
|
539
543
|
if (!hdoc.valid_url(links[i])) {
|
540
544
|
// Could be a relative path, check image exists
|
541
|
-
doesFileExist(source_path, htmlFile, links[i],
|
545
|
+
doesFileExist(source_path, htmlFile, links[i], markdown_paths.relativePath, markdown_content);
|
542
546
|
} else {
|
543
547
|
messages[htmlFile.relativePath].push(
|
544
548
|
`Image link is a properly formatted external URL: ${links[i]}`,
|
@@ -551,7 +555,7 @@ const e = require("express");
|
|
551
555
|
);
|
552
556
|
} catch (e) {
|
553
557
|
// Handle errors
|
554
|
-
const error_message = processErrorMessage(`External image link error: ${links[i]} - ${e.message}`,
|
558
|
+
const error_message = processErrorMessage(`External image link error: ${links[i]} - ${e.message}`, markdown_paths.relativePath, markdown_content, links[i]);
|
555
559
|
errors[htmlFile.relativePath].push(error_message);
|
556
560
|
}
|
557
561
|
}
|
@@ -559,7 +563,7 @@ const e = require("express");
|
|
559
563
|
};
|
560
564
|
|
561
565
|
const checkTags = async (htmlFile) => {
|
562
|
-
const
|
566
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
563
567
|
// Check if file is excluded from tag check
|
564
568
|
const file_no_ext = htmlFile.relativePath.replace(
|
565
569
|
path.extname(htmlFile.relativePath),
|
@@ -582,7 +586,7 @@ const e = require("express");
|
|
582
586
|
error_msg += h1_tags[i].text();
|
583
587
|
if (i < h1_tags.length - 1) error_msg += "; ";
|
584
588
|
}
|
585
|
-
errors[htmlFile.relativePath].push(`${
|
589
|
+
errors[htmlFile.relativePath].push(`${markdown_paths.relativePath} - ${error_msg}`);
|
586
590
|
}
|
587
591
|
};
|
588
592
|
|
@@ -608,8 +612,8 @@ const e = require("express");
|
|
608
612
|
};
|
609
613
|
|
610
614
|
const isRelativePath = (source_path, html_path, relative_path) => {
|
611
|
-
const
|
612
|
-
const markdown_content = fs.readFileSync(
|
615
|
+
const markdown_paths = getMDPathFromHtmlPath(html_path);
|
616
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
613
617
|
|
614
618
|
const rel_path_ext = path.extname(relative_path);
|
615
619
|
const response = {
|
@@ -660,7 +664,7 @@ const e = require("express");
|
|
660
664
|
}
|
661
665
|
}
|
662
666
|
if (response.has_md_extension || response.has_html_extension) {
|
663
|
-
const error_message = processErrorMessage(`Relative link has ${rel_path_ext} extension, but should not: ${relative_path}`,
|
667
|
+
const error_message = processErrorMessage(`Relative link has ${rel_path_ext} extension, but should not: ${relative_path}`, markdown_paths.relativePath, markdown_content, relative_path);
|
664
668
|
errors[html_path.relativePath].push(error_message);
|
665
669
|
return;
|
666
670
|
}
|
@@ -679,11 +683,11 @@ const e = require("express");
|
|
679
683
|
const redir = checkRedirect(source_path, relpath);
|
680
684
|
if (redir.exists) {
|
681
685
|
if (redir.error !== null) {
|
682
|
-
const error_message = processErrorMessage(`${redir.error}: ${relative_path}`,
|
686
|
+
const error_message = processErrorMessage(`${redir.error}: ${relative_path}`, markdown_paths.relativePath, markdown_content, clean_relative_path);
|
683
687
|
errors[html_path.relativePath].push(error_message);
|
684
688
|
}
|
685
689
|
} else {
|
686
|
-
const error_message = processErrorMessage(`Link path does not exist: ${relative_path}`,
|
690
|
+
const error_message = processErrorMessage(`Link path does not exist: ${relative_path}`, markdown_paths.relativePath, markdown_content, clean_relative_path);
|
687
691
|
errors[html_path.relativePath].push(error_message);
|
688
692
|
}
|
689
693
|
};
|