hdoc-tools 0.15.3 → 0.17.0

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
@@ -15,7 +15,8 @@
15
15
  hdoc_index = require(path.join(__dirname, 'hdoc-db.js')),
16
16
  {
17
17
  zip
18
- } = require('zip-a-folder');
18
+ } = require('zip-a-folder'),
19
+ xmlFormat = require('xml-formatter');
19
20
 
20
21
  const h_tags_to_search = ['h1', 'h2', 'h3'],
21
22
  doc_header_template_path = path.join(__dirname, 'templates', 'doc-header.html'),
@@ -302,7 +303,7 @@
302
303
 
303
304
  // Pull in external includes
304
305
  const includes_processed = await hdoc.process_includes(file_path.path, md_txt);
305
- md_txt = includes_processed.body;
306
+ md_txt = includes_processed.body.toString();
306
307
  includes_found += includes_processed.found;
307
308
  includes_success += includes_processed.success;
308
309
  includes_failed += includes_processed.failed;
@@ -337,8 +338,13 @@
337
338
  links: true
338
339
  });
339
340
 
341
+ // Tidy up ```json and ```xml code tags
342
+
343
+ if (md_txt.includes('```json') || md_txt.includes('```xml'))
344
+ md_txt = tidy_code_tags(md_txt, file_path.relativePath);
345
+
340
346
  // Render markdown into HTML
341
- let html_txt = md.render(md_txt.toString());
347
+ let html_txt = md.render(md_txt);
342
348
 
343
349
  // Prepare frontmatter headers
344
350
  let fm_headers = [];
@@ -541,6 +547,44 @@
541
547
  return false;
542
548
  };
543
549
 
550
+ const tidy_code_tags = function (markdown, file) {
551
+ const json_to_tidy = markdown.match(/```json(\s|.)*?```/g);
552
+ if (json_to_tidy && json_to_tidy.length > 0) {
553
+ for (let i = 0; i < json_to_tidy.length; i++) {
554
+ if (json_to_tidy[i] !== '') {
555
+ let json_tidy = json_to_tidy[i].replace('```json', '').replace('```', '');
556
+ try {
557
+ json_tidy = JSON.stringify(JSON.parse(json_tidy), null, 2);
558
+ } catch (e) {
559
+ console.log(`[WARNING] Could not tidy JSON in file [${file}]: ${e}`);
560
+ }
561
+ markdown = markdown.replace(json_to_tidy[i], '```json\n' + json_tidy + '\n```');
562
+ }
563
+ }
564
+ }
565
+
566
+ const xml_to_tidy = markdown.match(/```xml(\s|.)*?```/g);
567
+ if (xml_to_tidy && xml_to_tidy.length > 0) {
568
+ for (let i = 0; i < xml_to_tidy.length; i++) {
569
+ if (xml_to_tidy[i] !== '') {
570
+ const xml_tidy = xml_to_tidy[i].replace('```xml', '').replace('```', '');
571
+ let new_xml_string = xml_tidy;
572
+ try {
573
+ new_xml_string = xmlFormat(xml_tidy, {
574
+ indentation: ' ',
575
+ collapseContent: true,
576
+ lineSeparator: '\n'
577
+ });
578
+ } catch (e) {
579
+ console.log(`[WARNING] Could not tidy XML in file [${file}]: ${e}`);
580
+ }
581
+ markdown = markdown.replace(xml_to_tidy[i], '```xml\n' + new_xml_string + '\n```');
582
+ }
583
+ }
584
+ }
585
+ return markdown;
586
+ };
587
+
544
588
  const process_doc_header = function (fm_headers, doc_path, template, h1) {
545
589
  let wip_doc_header = template;
546
590
  let used_h1 = false;
package/hdoc-validate.js CHANGED
@@ -194,6 +194,32 @@
194
194
  return nav_errors;
195
195
  };
196
196
 
197
+ const checkRedirects = async function (source_path) {
198
+ let errors = [];
199
+ for (const key in redirects) {
200
+ if (redirects.hasOwnProperty(key)) {
201
+ let redir_locations = [
202
+ path.join(source_path, redirects[key].location + '.md'),
203
+ path.join(source_path, redirects[key].location, 'index.md'),
204
+ path.join(source_path, redirects[key].location + '.html'),
205
+ path.join(source_path, redirects[key].location + '.htm'),
206
+ path.join(source_path, redirects[key].location, 'index.html'),
207
+ path.join(source_path, redirects[key].location, 'index.htm')
208
+ ];
209
+ let redir_location_ok = false;
210
+ for (let i = 0; i < redir_locations.length; i++) {
211
+ if (fs.existsSync(redir_locations[i])) {
212
+ redir_location_ok = true;
213
+ break;
214
+ }
215
+ }
216
+ if (!redir_location_ok)
217
+ errors.push(`Redirect location does not exist: ${redirects[key].location}`);
218
+ }
219
+ }
220
+ return errors;
221
+ };
222
+
197
223
  const checkRedirect = function (source_path, nav_path) {
198
224
  let response = {
199
225
  exists: false,
@@ -484,6 +510,10 @@
484
510
  const nav_errors = await checkNavigation(source_path, nav_items, exclude_spellcheck);
485
511
  if (nav_errors.length > 0) meta_errors.push(...nav_errors);
486
512
 
513
+ // Check redirects
514
+ const redirect_errors = await checkRedirects(source_path);
515
+ if (redirect_errors.length > 0) meta_errors.push(...redirect_errors);
516
+
487
517
  if (meta_errors.length > 0) {
488
518
  console.log('\r\n-----------------------');
489
519
  console.log(' Validation Output ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.15.3",
3
+ "version": "0.17.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -58,6 +58,7 @@
58
58
  "stream": "0.0.2",
59
59
  "true-case-path": "^2.2.1",
60
60
  "words-count": "^2.0.2",
61
+ "xml-formatter": "^3.6.0",
61
62
  "zip-a-folder": "^1.1.5"
62
63
  }
63
64
  }