hdoc-tools 0.8.3 → 0.8.5

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
@@ -23,7 +23,8 @@ const {
23
23
  'book_audience',
24
24
  'book_tags',
25
25
  'doc_title',
26
- 'doc_content'
26
+ 'doc_content',
27
+ 'doc_preview'
27
28
  ];
28
29
 
29
30
  let conversion_attempted = 0,
@@ -183,8 +184,10 @@ const {
183
184
  fs.writeFile(target_file, html_txt, function writeJSON(err) {
184
185
  if (err) return console.log('Error writing:', target_file, '\r\n', err);
185
186
  });
186
-
187
- index_records.push({relative_path: relative_path, index_html: hdoc_index.transform_html_for_index(html_txt)});
187
+
188
+ const index_details = hdoc_index.transform_html_for_index(html_txt);
189
+
190
+ index_records.push({relative_path: relative_path, index_html: index_details});
188
191
 
189
192
  // Delete MD file from _work path
190
193
  try {
@@ -306,41 +309,44 @@ const {
306
309
  }
307
310
 
308
311
  // Now build the index
309
- console.log('Performing SQlite index creation...\n');
312
+ console.log('Performing SQlite index creation...');
310
313
  let db_name = path.join(work_path, docId, 'index.db');
311
314
  const db = new Database(db_name);
312
- console.log(`Database created: ${db_name}`);
315
+ console.log(`\nDatabase created: ${db_name}`);
313
316
 
314
317
  // Now add the table
315
318
  const table_name = 'hdoc_index';
316
319
  const table_created = hdoc_index.create_virtual_table(db, table_name, index_cols);
317
320
 
318
321
  if (table_created !== null) {
319
- console.log(`Error creating table: ${table_created}`);
322
+ console.log(`\nError creating table: ${table_created}`);
320
323
  } else {
321
- console.log(`Virtual table created: ${table_name}`);
324
+ console.log(`\nVirtual table created: ${table_name}`);
322
325
  if (!hdocbook_config.tags) hdocbook_config.tags = [];
323
326
  let index_success_count = 0;
324
327
  for (let i = 0; i < index_records.length; i++) {
328
+ let index_path_name = index_records[i].relative_path.replace('\\', '/').replace(`${hdocbook_config.docId}/`, '');
329
+ index_path_name = index_path_name.replace(path.extname(index_records[i].relative_path), '');
325
330
  const index_vals = [
326
- index_records[i].relative_path.replace('\\', '/').replace(`${hdocbook_config.docId}/`, ''),
331
+ index_path_name,
327
332
  hdocbook_config.docId,
328
333
  hdocbook_config.audience.join(','),
329
334
  hdocbook_config.tags.join(','),
330
335
  index_records[i].index_html.fm_props.title,
331
- index_records[i].index_html.text
336
+ index_records[i].index_html.text,
337
+ index_records[i].index_html.preview,
332
338
  ];
333
- let new_record_id = hdoc_index.insert_record(db, table_name, index_cols, index_vals, hdocbook_config.docId, index_records[i].index_html.fm_props.title);
334
- if (!new_record_id) {
335
- console.log(`Index record creation failed - ${hdocbook_config.docId}/${index_records[i].index_html.fm_props.title}: ${e}`);
339
+ const index_response = hdoc_index.insert_record(db, table_name, index_cols, index_vals, hdocbook_config.docId, index_records[i].index_html.fm_props.title);
340
+ if (!index_response.success) {
341
+ console.log(`Index record creation failed - ${hdocbook_config.docId}/${index_records[i].index_html.fm_props.title}: ${index_response.error}`);
336
342
  continue;
337
343
  }
338
344
  index_success_count++;
339
345
  if (verbose) {
340
- console.log(`Inserted index record ${new_record_id}: ${hdocbook_config.docId} - ${index_records[i].index_html.fm_props.title}`);
346
+ console.log(`Inserted index record ${index_response.row_id}: ${hdocbook_config.docId} - ${index_records[i].index_html.fm_props.title}`);
341
347
  }
342
348
  }
343
- console.log(`\nIndex Build Complete. ${index_success_count} records created.`);
349
+ console.log(`\nIndex Build Complete: ${index_success_count} records created.`);
344
350
  }
345
351
 
346
352
  try {
package/hdoc-db.js CHANGED
@@ -1,7 +1,8 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
- const html2text = require('html-to-text'),
4
+ const ellipsize = require('ellipsize'),
5
+ html2text = require('html-to-text'),
5
6
  path = require('path'),
6
7
  hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
8
 
@@ -22,6 +23,11 @@
22
23
  };
23
24
 
24
25
  exports.insert_record = function (db, table, columns, values, book_id, doc_title) {
26
+ let response = {
27
+ success: false,
28
+ row_id: 0,
29
+ error: null
30
+ };
25
31
  let queryProps = [];
26
32
  queryProps.push(`INSERT INTO ${table}`);
27
33
  let cols = '(';
@@ -43,15 +49,18 @@
43
49
  try {
44
50
  const stmt = db.prepare(queryProps.join('\n'));
45
51
  const info = stmt.run(values);
46
- return info.lastInsertRowid;
52
+ response.row_id = info.lastInsertRowid;
53
+ response.success = true;
47
54
  } catch (e) {
48
- return false;
55
+ response.error = e;
49
56
  }
57
+ return response;
50
58
  };
51
59
 
52
60
  exports.transform_html_for_index = function (html_txt) {
53
61
  let response = {
54
62
  text: '',
63
+ preview: '',
55
64
  fm_props: {}
56
65
  };
57
66
 
@@ -61,9 +70,21 @@
61
70
 
62
71
  // Convert HTML into plain text
63
72
  response.text = html2text.convert(html_txt, {
73
+ ignoreHref: true,
74
+ ignoreImage: true,
75
+ uppercaseHeadings: false,
64
76
  wordwrap: null
65
77
  });
66
78
 
79
+ // Convert HTML into preview text
80
+ response.preview = html2text.convert(html_txt, {
81
+ baseElement: 'p',
82
+ ignoreHref: true,
83
+ ignoreImage: true,
84
+ uppercaseHeadings: false,
85
+ wordwrap: null
86
+ });
87
+ response.preview = ellipsize(response.preview, 200).replace(/(?:\r\n|\r|\n)/g, ' ');
67
88
  return response;
68
89
  };
69
90
 
package/hdoc-module.js CHANGED
@@ -172,13 +172,15 @@
172
172
  // We have a Frontmatter header - return each property in an array
173
173
  const fm_properties = child.data.split(/\r?\n/);
174
174
  for (let i = 0; i < fm_properties.length; i++) {
175
- const property_details = fm_properties[i].split(/:(.*)/s);
176
- if (property_details.length > 1) {
177
- let prop_val = property_details[i].trim();
178
- if (/^".*"$/.test(prop_val)) {
179
- prop_val = prop_val.substring(1, prop_val.length - 1);
175
+ if (fm_properties[i].includes(':')) {
176
+ const property_details = fm_properties[i].split(/:(.*)/s);
177
+ if (property_details.length > 1) {
178
+ let prop_val = property_details[1].trim();
179
+ if (/^".*"$/.test(prop_val)) {
180
+ prop_val = prop_val.substring(1, prop_val.length - 1);
181
+ }
182
+ response.fm_properties[property_details[0].trim().toLowerCase()] = prop_val;
180
183
  }
181
- response.fm_properties[property_details[0].trim().toLowerCase()] = prop_val;
182
184
  }
183
185
  }
184
186
 
package/hdoc-stats.js CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  // Required modules
6
6
  // /const { STATUS_CODES } = require('http');
7
- const fs = require('fs');
8
- const path = require('path');
9
- const dree = require('dree');
10
- const html2text = require('html-to-text');
11
- const wordsCount = require('words-count').default;
7
+ const fs = require('fs'),
8
+ path = require('path'),
9
+ dree = require('dree'),
10
+ html2text = require('html-to-text'),
11
+ wordsCount = require('words-count').default;
12
12
 
13
13
  // Regex to remove Hornbill-specific tags
14
14
  const hbMDTagRegex = /(:{3}[ ]note)|(:{3}[ ]tip)|(:{3}[ ]important)|(:{3}[ ]caution)|(:{3}[ ]warning)|(:{3})/g;
@@ -103,6 +103,12 @@
103
103
  console.error('Could not load book configuration:\r\n', e);
104
104
  return;
105
105
  }
106
+ // Load markdown-it module
107
+ const md = require('markdown-it')({
108
+ html: true,
109
+ linkify: true,
110
+ typographer: true
111
+ });
106
112
 
107
113
  // Scan content path directory, send file info to callback for processing
108
114
  dree.scan(bookPath, dreeOptions, fileCallback);
@@ -110,7 +116,6 @@
110
116
  // Load markdown file
111
117
  let md_txt = fs.readFileSync(element.path, 'utf8');
112
118
 
113
- // Render markdown into HTML
114
119
  var html_txt = md.render(md_txt.toString());
115
120
  const text = html2text.convert(html_txt, {
116
121
  wordwrap: null
package/hdoc-validate.js CHANGED
@@ -105,7 +105,7 @@ const parseLinkDestination = require('markdown-it/lib/helpers/parse_link_destina
105
105
  }
106
106
 
107
107
  // Build list content for Google
108
- listContent += `/${htmlFiles[i].relativePath}`;
108
+ listContent += `/${htmlFiles[i].relativePath.replace(path.extname(htmlFiles[i].relativePath), '')}`;
109
109
  if (i < htmlFiles.length - 1) {
110
110
  listContent += '\r\n';
111
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -33,6 +33,7 @@
33
33
  "cheerio": "^1.0.0-rc.12",
34
34
  "cookie-parser": "^1.4.6",
35
35
  "dree": "^3.4.2",
36
+ "ellipsize": "^0.5.1",
36
37
  "express": "^4.18.2",
37
38
  "fs-extra": "^11.1.0",
38
39
  "highlight.js": "^11.6.0",
@@ -44,7 +44,7 @@ h5,
44
44
  h6 {
45
45
  margin: 0;
46
46
  line-height: normal;
47
- /*font-size: var(--htl-default-font-size);*/
47
+ font-size: revert; /* let browser handle it */
48
48
  font-weight: 400;
49
49
  }
50
50
 
@@ -105,6 +105,9 @@ code,
105
105
  kbd,
106
106
  samp {
107
107
  font-family: var(--htl-font-family-mono);
108
+ font-size: var(--htl-default-font-size);
109
+ font-weight: 400;
110
+ overflow: unset;
108
111
  }
109
112
 
110
113
  img,
package/ui/index.html CHANGED
@@ -185,14 +185,14 @@
185
185
  <div class="injected-document-content"></div>
186
186
 
187
187
  <!-- table of contents -->
188
- <div v-if="docApp.tableOfContents.length" class="injected-document-toc">
189
- <div class="panel-header">
188
+ <div v-if="docApp.keepTocLayout" class="injected-document-toc">
189
+ <div v-if="docApp.tableOfContents.length" class="panel-header">
190
190
  <span class="icon">
191
191
  <i class="bi bi-list-ul"></i>
192
192
  </span>
193
193
  <span class="title">In This Document</span>
194
194
  </div>
195
- <div class="panel-content">
195
+ <div v-if="docApp.tableOfContents.length" class="panel-content">
196
196
  <div v-for="tocItem in docApp.tableOfContents" :class="tocItem.tagName">
197
197
  <a :href="tocItem.href">{{tocItem.eleText}}</a>
198
198
  </div>
@@ -257,17 +257,15 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
257
257
  {
258
258
  $("#DocContent").addClass(frontmatterData.layout);
259
259
  global.lastLayoutClass = frontmatterData.layout;
260
-
261
- //-- if layout supports toc (expects layout to have name "<layoutname>-toc")
262
- if(frontmatterData.layout.substr(frontmatterData.layout.length - 4)==="-toc")
263
- {
264
- //generateTableOfContentsFromDoc();
265
- }
266
-
267
260
  }
268
261
 
269
- //--generate toc for all layouts that have h2/h3
270
- generateTableOfContentsFromDoc();
262
+ //--generate toc for all layouts that have h2/h3
263
+ view.docApp.keepTocLayout = (frontmatterData.layout == "article-no-toc");
264
+ if(!frontmatterData.layout || frontmatterData.layout==="article" || frontmatterData.layout==="article-toc")
265
+ {
266
+ view.docApp.keepTocLayout = true;
267
+ generateTableOfContentsFromDoc();
268
+ }
271
269
 
272
270
  //-- do any code highlighting
273
271
  document.querySelectorAll('pre code').forEach((el) => {
@@ -439,7 +437,7 @@ async function fetchJsonFile(strFilePath)
439
437
  //-- THE INIT APP CALLED FROM index.html
440
438
  var view = new Vue({
441
439
  el: '#vDocDevApp',
442
- data: {updateCounter:0,bookId:"", docApp:{book:{},navSections:[],tableOfContents:[]}},
440
+ data: {updateCounter:0,bookId:"", docApp:{keepTocLayout:false,book:{},navSections:[],tableOfContents:[]}},
443
441
  methods:docAppMethods,
444
442
  directives: {
445
443
  somedirectivename: {