hdoc-tools 0.9.4 → 0.9.6
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 +6 -0
- package/hdoc-build.js +9 -17
- package/hdoc-help.js +8 -5
- package/hdoc-init.js +5 -0
- package/hdoc-validate.js +98 -43
- package/hdoc.js +1 -1
- package/package.json +3 -2
- package/templates/init/.gitignore +7 -0
- package/ui/css/theme-default/styles/components/content.css +8 -1
- package/ui/index.html +1 -1
package/README.md
CHANGED
@@ -39,6 +39,12 @@ Performs a local build of the book, validates the links and static content are p
|
|
39
39
|
|
40
40
|
If the -v switch is provided, then a more verbose output is provided, which includes a list of all HTML files created and checked for embedded links and static content.
|
41
41
|
|
42
|
+
### build
|
43
|
+
|
44
|
+
Performs a minimum local build of the book, then validates the links and static content are present and correct.
|
45
|
+
|
46
|
+
If the -v switch is provided, then a more verbose output is provided, which includes a list of all HTML files created and checked for embedded links and static content.
|
47
|
+
|
42
48
|
### serve
|
43
49
|
|
44
50
|
Starts a local web server on port 3000, serving the book content.
|
package/hdoc-build.js
CHANGED
@@ -570,10 +570,6 @@
|
|
570
570
|
const nav_a = nav_items[a];
|
571
571
|
const parent_a = nav_a.text;
|
572
572
|
if (nav_a.link) {
|
573
|
-
if (nav_a.link.includes('\\')) {
|
574
|
-
console.log(`Navigation items should not contain backslashes: ${nav_a.link}`);
|
575
|
-
process.exit(1);
|
576
|
-
}
|
577
573
|
bc[nav_a.link] = [{
|
578
574
|
text: nav_a.text,
|
579
575
|
link: nav_a.link
|
@@ -584,10 +580,6 @@
|
|
584
580
|
const nav_b = nav_a.items[b];
|
585
581
|
const parent_b = nav_b.text;
|
586
582
|
if (nav_b.link) {
|
587
|
-
if (nav_b.link.includes('\\')) {
|
588
|
-
console.log(`Navigation items should not contain backslashes: ${nav_b.link}`);
|
589
|
-
process.exit(1);
|
590
|
-
}
|
591
583
|
if (bc[nav_a.link]) {
|
592
584
|
bc[nav_b.link] = bc[nav_a.link];
|
593
585
|
} else {
|
@@ -607,10 +599,6 @@
|
|
607
599
|
const nav_c = nav_b.items[c];
|
608
600
|
const parent_c = nav_c.text;
|
609
601
|
if (nav_c.link) {
|
610
|
-
if (nav_c.link.includes('\\')) {
|
611
|
-
console.log(`Navigation items should not contain backslashes: ${nav_c.link}`);
|
612
|
-
process.exit(1);
|
613
|
-
}
|
614
602
|
if (bc[nav_b.link]) {
|
615
603
|
bc[nav_c.link] = bc[nav_b.link];
|
616
604
|
} else {
|
@@ -633,10 +621,6 @@
|
|
633
621
|
for (let d = 0; d < nav_c.items.length; d++) {
|
634
622
|
const nav_d = nav_c.items[d];
|
635
623
|
if (nav_d.link) {
|
636
|
-
if (nav_d.link.includes('\\')) {
|
637
|
-
console.log(`Navigation items should not contain backslashes: ${nav_d.link}`);
|
638
|
-
process.exit(1);
|
639
|
-
}
|
640
624
|
if (bc[nav_c.link]) {
|
641
625
|
bc[nav_d.link] = bc[nav_c.link];
|
642
626
|
} else {
|
@@ -690,7 +674,13 @@
|
|
690
674
|
// Load the hdocbook-project.json file to get the docId
|
691
675
|
// use the docId to get the book config
|
692
676
|
const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
|
693
|
-
|
677
|
+
try {
|
678
|
+
hdocbook_project = require(hdocbook_project_config_path);
|
679
|
+
} catch (e) {
|
680
|
+
console.log('File not found: hdocbook-project.json\n');
|
681
|
+
console.log('hdoc build/validate needs to be run in the root of a HDoc Book.\n');
|
682
|
+
process.exit(1);
|
683
|
+
}
|
694
684
|
doc_id = hdocbook_project.docId;
|
695
685
|
|
696
686
|
if (!validate && hdocbook_project.pdfGeneration !== undefined && hdocbook_project.pdfGeneration.enable !== undefined) {
|
@@ -833,6 +823,8 @@
|
|
833
823
|
} catch (e) {
|
834
824
|
console.log('\nError creating ZIP: ' + e);
|
835
825
|
}
|
826
|
+
} else {
|
827
|
+
console.log('\nValidation Complete\n');
|
836
828
|
}
|
837
829
|
};
|
838
830
|
})();
|
package/hdoc-help.js
CHANGED
@@ -11,20 +11,23 @@ Command Line Usage
|
|
11
11
|
|
12
12
|
Commands
|
13
13
|
|
14
|
+
- build
|
15
|
+
Performs a local build of the book, and outputs as a ZIP file
|
16
|
+
|
14
17
|
- help
|
15
18
|
Outputs available arguments and switches
|
16
19
|
|
17
20
|
- init
|
18
21
|
Initializes a new HDocBook project from a template, using runtime input variables
|
19
22
|
|
23
|
+
- serve
|
24
|
+
Starts a local web server on port 3000, serving the content. Supports a -port N to use a different port
|
25
|
+
|
20
26
|
- stats
|
21
27
|
Returns statistics regarding the book you are working on. Supports a -v switch for verbose output
|
22
28
|
|
23
|
-
-
|
24
|
-
|
25
|
-
|
26
|
-
- serve
|
27
|
-
Starts a local web server on port 3000, serving the content. Supports a -port N to use a different port
|
29
|
+
- validate
|
30
|
+
Validates the book content
|
28
31
|
|
29
32
|
Example
|
30
33
|
|
package/hdoc-init.js
CHANGED
@@ -123,7 +123,12 @@
|
|
123
123
|
// those files into place, with a few variable replacements.
|
124
124
|
|
125
125
|
console.log('Hornbill HDocBook Init', '\r\n');
|
126
|
+
|
127
|
+
const curr_dirs = source_path.split(path.sep);
|
128
|
+
let doc_id = curr_dirs[curr_dirs.length - 1];
|
129
|
+
|
126
130
|
prompt.start();
|
131
|
+
promptProps[0].default = doc_id;
|
127
132
|
prompt.get(promptProps, function (err, result) {
|
128
133
|
if (err) {
|
129
134
|
console.error(err);
|
package/hdoc-validate.js
CHANGED
@@ -11,9 +11,14 @@
|
|
11
11
|
hdoc = require(path.join(__dirname, 'hdoc-module.js')),
|
12
12
|
translator = require('american-british-english-translator');
|
13
13
|
|
14
|
-
const
|
15
|
-
|
16
|
-
|
14
|
+
const agent = new https.Agent({
|
15
|
+
rejectUnauthorized: false
|
16
|
+
}),
|
17
|
+
spellcheck_options = {
|
18
|
+
british: true,
|
19
|
+
spelling: true
|
20
|
+
},
|
21
|
+
regex_nav_paths = /[a-z-\/]+/g;
|
17
22
|
|
18
23
|
let prod_families = {};
|
19
24
|
|
@@ -34,27 +39,21 @@
|
|
34
39
|
throw `Unexpected Status ${prods.status}`;
|
35
40
|
}
|
36
41
|
} catch (e) {
|
37
|
-
// Handle errors
|
38
42
|
console.log(`Error returning product families: ${e}`);
|
39
43
|
return false;
|
40
44
|
}
|
41
45
|
return true;
|
42
46
|
};
|
43
47
|
|
44
|
-
const
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (rel_source.includes('/_work/')) {
|
54
|
-
rel_source = rel_source.split('/_work/')[1];
|
55
|
-
}
|
56
|
-
|
57
|
-
const translate_output = translator.translate(text, options);
|
48
|
+
const spellcheckHTML = async function (htmlFile, excludes) {
|
49
|
+
const htmlBody = fs.readFileSync(htmlFile.path, 'utf8');
|
50
|
+
const text = html2text.convert(htmlBody, {
|
51
|
+
wordwrap: null,
|
52
|
+
selectors: [
|
53
|
+
{ selector: 'code', format: 'skip'}
|
54
|
+
]
|
55
|
+
});
|
56
|
+
const translate_output = translator.translate(text, spellcheck_options);
|
58
57
|
if(Object.keys(translate_output).length){
|
59
58
|
for (const key in translate_output) {
|
60
59
|
if (translate_output.hasOwnProperty(key)) {
|
@@ -62,10 +61,10 @@
|
|
62
61
|
for (let i = 0; i < translate_output[key].length; i++) {
|
63
62
|
for (const spelling in translate_output[key][i]) {
|
64
63
|
if (translate_output[key][i].hasOwnProperty(spelling)) {
|
65
|
-
if (!excludes[
|
66
|
-
errors[
|
67
|
-
} else if (!excludes[
|
68
|
-
errors[
|
64
|
+
if (!excludes[htmlFile.relativePath]) {
|
65
|
+
errors[htmlFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
66
|
+
} else if (!excludes[htmlFile.relativePath].includes(spelling.toLowerCase())) {
|
67
|
+
errors[htmlFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
69
68
|
}
|
70
69
|
}
|
71
70
|
}
|
@@ -75,15 +74,59 @@
|
|
75
74
|
}
|
76
75
|
};
|
77
76
|
|
78
|
-
const
|
79
|
-
|
80
|
-
const
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
const checkNavigation = async function (doc_id, flat_nav) {
|
78
|
+
let nav_errors = [];
|
79
|
+
for (const key in flat_nav) {
|
80
|
+
if (flat_nav.hasOwnProperty(key)) {
|
81
|
+
// doc paths should only contain a-z - characters
|
82
|
+
const invalid_chars = key.replace(regex_nav_paths, '');
|
83
|
+
if (invalid_chars !== '') {
|
84
|
+
nav_errors.push(`Navigation path [${key}] contains the following invalid characters: [${[...invalid_chars].join('] [')}]`);
|
85
|
+
}
|
86
|
+
|
87
|
+
//Validate path
|
88
|
+
const paths = key.split('/');
|
89
|
+
for (let i = 0; i < paths.length; i++) {
|
90
|
+
const path_words = paths[i].split('-');
|
91
|
+
for (let j = 0; j < path_words.length; j++) {
|
92
|
+
const translate_output = translator.translate(path_words[j], spellcheck_options);
|
93
|
+
if(Object.keys(translate_output).length){
|
94
|
+
for (const spell_val in translate_output) {
|
95
|
+
if (translate_output.hasOwnProperty(spell_val)) {
|
96
|
+
for (const spelling in translate_output[spell_val][0]) {
|
97
|
+
if (translate_output[spell_val][0].hasOwnProperty(spelling)) {
|
98
|
+
nav_errors.push(`Navigation path [${key}] key contains a British English spelling: ${spelling} should be ${translate_output[spell_val][0][spelling].details}`);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
// Validate display names/bookmarks
|
108
|
+
for (let i = 0; i < flat_nav[key].length; i++) {
|
109
|
+
if (flat_nav[key][i].link === key) {
|
110
|
+
const translate_output = translator.translate(flat_nav[key][i].text, spellcheck_options);
|
111
|
+
if(Object.keys(translate_output).length){
|
112
|
+
for (const spell_val in translate_output) {
|
113
|
+
if (translate_output.hasOwnProperty(spell_val)) {
|
114
|
+
for (let j = 0; j < translate_output[spell_val].length; j++) {
|
115
|
+
for (const spelling in translate_output[spell_val][j]) {
|
116
|
+
if (translate_output[spell_val][j].hasOwnProperty(spelling)) {
|
117
|
+
nav_errors.push(`Navigation path [${key}] display text contains a British English spelling: ${spelling} should be ${translate_output[spell_val][j][spelling].details}`);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return nav_errors;
|
87
130
|
};
|
88
131
|
|
89
132
|
const checkLinks = async function (source_path, htmlFile, links, hdocbook_config) {
|
@@ -163,7 +206,7 @@
|
|
163
206
|
symbolicLinks: false
|
164
207
|
};
|
165
208
|
|
166
|
-
// File
|
209
|
+
// File scan callback
|
167
210
|
const fileCallback = function (element) {
|
168
211
|
html_files.push(element);
|
169
212
|
};
|
@@ -256,31 +299,43 @@
|
|
256
299
|
|
257
300
|
// Check product family
|
258
301
|
let valid_product = false;
|
302
|
+
let meta_errors = [];
|
259
303
|
for (let i = 0; i < prod_families.products.length; i++) {
|
260
304
|
if (prod_families.products[i].id === hdocbook_config.productFamily) {
|
261
305
|
valid_product = true;
|
262
306
|
}
|
263
307
|
}
|
264
308
|
if (!valid_product) {
|
309
|
+
meta_errors.push(`Incorrect productFamily: ${hdocbook_config.productFamily}`)
|
310
|
+
}
|
311
|
+
|
312
|
+
// Check navigation spellings
|
313
|
+
const nav_errors = await checkNavigation(doc_id, nav_items);
|
314
|
+
if (nav_errors.length > 0) meta_errors.push(...nav_errors);
|
315
|
+
|
316
|
+
if (meta_errors.length > 0) {
|
265
317
|
console.log('\r\n-----------------------');
|
266
318
|
console.log(' Validation Output ');
|
267
|
-
console.log('
|
268
|
-
console.log(
|
269
|
-
console.log(`\r\
|
319
|
+
console.log('-----------------------');
|
320
|
+
console.log()
|
321
|
+
console.log(`\r\n${meta_errors.length} Validation Errors Found\r\n`);
|
322
|
+
for (let i = 0; i < meta_errors.length; i++) {
|
323
|
+
console.log(`- ${meta_errors[i]}`);
|
324
|
+
}
|
270
325
|
return false;
|
271
326
|
}
|
272
327
|
|
273
328
|
if (hdocbook_project.validation) {
|
274
329
|
if (hdocbook_project.validation.exclude_links && hdocbook_project.validation.exclude_links instanceof Array) {
|
275
|
-
|
330
|
+
hdocbook_project.validation.exclude_links.forEach(function(excl_link) {
|
276
331
|
exclude_links[excl_link] = true;
|
277
332
|
});
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
333
|
+
}
|
334
|
+
if (hdocbook_project.validation.exclude_spellcheck && hdocbook_project.validation.exclude_spellcheck instanceof Array) {
|
335
|
+
hdocbook_project.validation.exclude_spellcheck.forEach(function(excl_sc) {
|
336
|
+
exclude_spellcheck[excl_sc.document_path] = excl_sc.words;
|
337
|
+
});
|
338
|
+
}
|
284
339
|
}
|
285
340
|
|
286
341
|
let listContent = '';
|
@@ -292,7 +347,7 @@
|
|
292
347
|
warnings[html_files[i].relativePath] = [];
|
293
348
|
|
294
349
|
// Check for Britishisms
|
295
|
-
await
|
350
|
+
await spellcheckHTML(html_files[i], exclude_spellcheck);
|
296
351
|
|
297
352
|
const links = getLinks(html_files[i]);
|
298
353
|
if (links.href.length === 0) {
|
package/hdoc.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdoc-tools",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.6",
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
5
5
|
"main": "hdoc.js",
|
6
6
|
"bin": {
|
@@ -21,7 +21,8 @@
|
|
21
21
|
"validateNodeVer.js",
|
22
22
|
"ui",
|
23
23
|
"custom_modules",
|
24
|
-
"templates"
|
24
|
+
"templates",
|
25
|
+
"templates/init/.gitignore"
|
25
26
|
],
|
26
27
|
"scripts": {
|
27
28
|
"preinstall": "node validateNodeVer",
|
@@ -75,13 +75,20 @@
|
|
75
75
|
}
|
76
76
|
|
77
77
|
|
78
|
-
/* style overrides to apply on screens that are
|
78
|
+
/* style overrides to apply on screens that are 1500px and wider */
|
79
79
|
@media (min-width: 1500px) {
|
80
80
|
|
81
81
|
.DocContent .injected-document-toc
|
82
82
|
{
|
83
83
|
display:inline-block;
|
84
84
|
}
|
85
|
+
|
86
|
+
/* if have toc layout and greater than 1500px then limit doc content to 900px to make room for toc */
|
87
|
+
.DocContent.article-toc .injected-document-content
|
88
|
+
{
|
89
|
+
width: 900px;
|
90
|
+
}
|
91
|
+
|
85
92
|
}
|
86
93
|
|
87
94
|
/* style overrides to apply on screens that are 1920px and wider */
|