hdoc-tools 0.16.0 → 0.17.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.
Files changed (2) hide show
  1. package/hdoc-build.js +47 -3
  2. package/package.json +3 -2
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -53,11 +53,12 @@
53
53
  "mime-types": "^2.1.35",
54
54
  "multer": "^1.4.5-lts.1",
55
55
  "prompt": "^1.3.0",
56
- "puppeteer": "^19.8.0",
56
+ "puppeteer": "^21.6.0",
57
57
  "retry": "^0.13.1",
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
  }