hdoc-tools 0.9.7 → 0.9.8

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-build.js CHANGED
@@ -45,6 +45,7 @@
45
45
  includes_failed = 0,
46
46
  index_records = [],
47
47
  md_files = [],
48
+ md_files_delete = [],
48
49
  static_html_files = [],
49
50
  work_path_content = '',
50
51
  verbose = false;
@@ -468,12 +469,9 @@
468
469
  pdf_size: pdf_size
469
470
  });
470
471
 
471
- // Delete MD file from _work path
472
- try {
473
- fs.unlinkSync(file_path.path);
474
- } catch (e) {
475
- console.log(`Error deleting ${file_path.path}: ${e}`);
476
- }
472
+ // Add MD file to delete queue
473
+ md_files_delete.push(file_path.path)
474
+
477
475
  conversion_success++;
478
476
  return true;
479
477
  }
@@ -789,6 +787,16 @@
789
787
  process.exit(1);
790
788
  }
791
789
 
790
+ // Delete markdown files
791
+ for (let i = 0; i < md_files_delete.length; i++) {
792
+ // Delete MD file from _work path
793
+ try {
794
+ fs.unlinkSync(md_files_delete[i]);
795
+ } catch (e) {
796
+ console.log(`Error deleting ${md_files_delete[i]}: ${e}`);
797
+ }
798
+ }
799
+
792
800
  // Add book read timing to the hdocbook.json
793
801
  hdocbook_config.readingTime = Math.ceil(book_read_time + ((book_read_time / 100) * 10));
794
802
  try {
package/hdoc-validate.js CHANGED
@@ -5,7 +5,6 @@
5
5
  cheerio = require('cheerio'),
6
6
  dree = require('dree'),
7
7
  fs = require('fs'),
8
- html2text = require('html-to-text'),
9
8
  https = require('https'),
10
9
  path = require('path'),
11
10
  hdoc = require(path.join(__dirname, 'hdoc-module.js')),
@@ -26,7 +25,8 @@
26
25
  messages = {},
27
26
  warnings = {},
28
27
  errorcount = 0,
29
- html_files = [],
28
+ html_to_validate = [],
29
+ md_to_validate = [],
30
30
  exclude_links = {},
31
31
  exclude_spellcheck = {};
32
32
 
@@ -45,14 +45,9 @@
45
45
  return true;
46
46
  };
47
47
 
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
- });
48
+ const spellcheckContent = async function (sourceFile, excludes) {
49
+ const text = fs.readFileSync(sourceFile.path, 'utf8');
50
+ const source_path = sourceFile.relativePath.replace('.'+sourceFile.extension, '');
56
51
  const translate_output = translator.translate(text, spellcheck_options);
57
52
  if(Object.keys(translate_output).length){
58
53
  for (const key in translate_output) {
@@ -61,10 +56,10 @@
61
56
  for (let i = 0; i < translate_output[key].length; i++) {
62
57
  for (const spelling in translate_output[key][i]) {
63
58
  if (translate_output[key][i].hasOwnProperty(spelling)) {
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}`);
59
+ if (!excludes[source_path]) {
60
+ errors[sourceFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
61
+ } else if (!excludes[source_path].includes(spelling.toLowerCase())) {
62
+ errors[sourceFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
68
63
  }
69
64
  }
70
65
  }
@@ -197,7 +192,7 @@
197
192
  const dreeOptions = {
198
193
  descendants: true,
199
194
  depth: 10,
200
- extensions: ['htm', 'html'],
195
+ extensions: ['htm', 'html','md'],
201
196
  hash: false,
202
197
  normalize: true,
203
198
  size: false,
@@ -208,7 +203,11 @@
208
203
 
209
204
  // File scan callback
210
205
  const fileCallback = function (element) {
211
- html_files.push(element);
206
+ if (element.extension.toLowerCase() === 'md') {
207
+ md_to_validate.push(element);
208
+ } else {
209
+ html_to_validate.push(element);
210
+ }
212
211
  };
213
212
 
214
213
  const isRelativePath = function (source_path, html_path, relative_path) {
@@ -338,32 +337,47 @@
338
337
  }
339
338
  }
340
339
 
340
+ // Do spellchecking on markdown files
341
+ let md_files_spellchecked = {};
342
+ for (let i = 0; i < md_to_validate.length; i++) {
343
+ // Initiate maps for errors and verbose messages for markdown file
344
+ errors[md_to_validate[i].relativePath] = [];
345
+ messages[md_to_validate[i].relativePath] = [];
346
+ warnings[md_to_validate[i].relativePath] = [];
347
+
348
+ await spellcheckContent(md_to_validate[i], exclude_spellcheck);
349
+ md_files_spellchecked[md_to_validate[i].relativePath.replace('.' + md_to_validate[i].extension, '')] = true;
350
+ }
351
+
352
+ // Perform rest of validation against HTML files
341
353
  let listContent = '';
342
- for (let i = 0; i < html_files.length; i++) {
354
+ for (let i = 0; i < html_to_validate.length; i++) {
343
355
 
344
356
  // Initiate maps for errors and verbose messages for HTML file
345
- errors[html_files[i].relativePath] = [];
346
- messages[html_files[i].relativePath] = [];
347
- warnings[html_files[i].relativePath] = [];
357
+ errors[html_to_validate[i].relativePath] = [];
358
+ messages[html_to_validate[i].relativePath] = [];
359
+ warnings[html_to_validate[i].relativePath] = [];
348
360
 
349
- // Check for Britishisms
350
- await spellcheckHTML(html_files[i], exclude_spellcheck);
361
+ // Check for British spellings in static HTML content
362
+ if (!md_files_spellchecked[html_to_validate[i].relativePath.replace('.' + html_to_validate[i].extension, '')]) {
363
+ await spellcheckContent(html_to_validate[i], exclude_spellcheck);
364
+ }
351
365
 
352
- const links = getLinks(html_files[i]);
366
+ const links = getLinks(html_to_validate[i]);
353
367
  if (links.href.length === 0) {
354
- messages[html_files[i].relativePath].push('No links found in file');
368
+ messages[html_to_validate[i].relativePath].push('No links found in file');
355
369
  } else {
356
- await checkLinks(source_path, html_files[i], links.href, hdocbook_config);
370
+ await checkLinks(source_path, html_to_validate[i], links.href, hdocbook_config);
357
371
  }
358
372
  if (links.img.length === 0) {
359
- messages[html_files[i].relativePath].push('No images found in file');
373
+ messages[html_to_validate[i].relativePath].push('No images found in file');
360
374
  } else {
361
- await checkImages(source_path, html_files[i], links.img);
375
+ await checkImages(source_path, html_to_validate[i], links.img);
362
376
  }
363
377
 
364
378
  // Build list content for Google
365
- listContent += `/${html_files[i].relativePath.replace(path.extname(html_files[i].relativePath), '')}`;
366
- if (i < html_files.length - 1) {
379
+ listContent += `/${html_to_validate[i].relativePath.replace(path.extname(html_to_validate[i].relativePath), '')}`;
380
+ if (i < html_to_validate.length - 1) {
367
381
  listContent += '\r\n';
368
382
  }
369
383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {