hdoc-tools 0.8.2 → 0.8.4
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 +35 -11
- package/hdoc-db.js +24 -3
- package/hdoc-module.js +9 -3
- package/hdoc-validate.js +1 -1
- package/package.json +2 -1
- package/ui/css/theme-default/styles/base.css +4 -1
- package/ui/index.html +3 -3
- package/ui/js/doc.hornbill.js +8 -10
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
|
-
|
|
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 {
|
|
@@ -205,6 +208,15 @@ const {
|
|
|
205
208
|
if (element.extension === 'md') {
|
|
206
209
|
md_files.push(element);
|
|
207
210
|
} else {
|
|
211
|
+
// File is html, see if there's a matching md file and if there is then ignore the html
|
|
212
|
+
let html_path = element.path.replace(path.extname(element.path), '.html');
|
|
213
|
+
if (fs.existsSync(html_path)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
html_path = element.path.replace(path.extname(element.path), '.htm');
|
|
217
|
+
if (fs.existsSync(html_path)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
208
220
|
static_html_files.push(element);
|
|
209
221
|
}
|
|
210
222
|
};
|
|
@@ -297,32 +309,44 @@ const {
|
|
|
297
309
|
}
|
|
298
310
|
|
|
299
311
|
// Now build the index
|
|
300
|
-
console.log('Performing SQlite index creation
|
|
312
|
+
console.log('Performing SQlite index creation...');
|
|
301
313
|
let db_name = path.join(work_path, docId, 'index.db');
|
|
302
314
|
const db = new Database(db_name);
|
|
303
|
-
console.log(
|
|
315
|
+
console.log(`\nDatabase created: ${db_name}`);
|
|
304
316
|
|
|
305
317
|
// Now add the table
|
|
306
318
|
const table_name = 'hdoc_index';
|
|
307
319
|
const table_created = hdoc_index.create_virtual_table(db, table_name, index_cols);
|
|
308
320
|
|
|
309
321
|
if (table_created !== null) {
|
|
310
|
-
console.log(
|
|
322
|
+
console.log(`\nError creating table: ${table_created}`);
|
|
311
323
|
} else {
|
|
312
|
-
console.log(
|
|
324
|
+
console.log(`\nVirtual table created: ${table_name}`);
|
|
313
325
|
if (!hdocbook_config.tags) hdocbook_config.tags = [];
|
|
326
|
+
let index_success_count = 0;
|
|
314
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), '');
|
|
315
330
|
const index_vals = [
|
|
316
|
-
|
|
331
|
+
index_path_name,
|
|
317
332
|
hdocbook_config.docId,
|
|
318
333
|
hdocbook_config.audience.join(','),
|
|
319
334
|
hdocbook_config.tags.join(','),
|
|
320
335
|
index_records[i].index_html.fm_props.title,
|
|
321
|
-
index_records[i].index_html.text
|
|
336
|
+
index_records[i].index_html.text,
|
|
337
|
+
index_records[i].index_html.preview,
|
|
322
338
|
];
|
|
323
|
-
hdoc_index.insert_record(db, table_name, index_cols, index_vals, hdocbook_config.docId, index_records[i].index_html.fm_props.title);
|
|
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}`);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
index_success_count++;
|
|
345
|
+
if (verbose) {
|
|
346
|
+
console.log(`Inserted index record ${index_response.row_id}: ${hdocbook_config.docId} - ${index_records[i].index_html.fm_props.title}`);
|
|
347
|
+
}
|
|
324
348
|
}
|
|
325
|
-
console.log(`\nIndex Build Complete
|
|
349
|
+
console.log(`\nIndex Build Complete: ${index_success_count} records created.`);
|
|
326
350
|
}
|
|
327
351
|
|
|
328
352
|
try {
|
package/hdoc-db.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const
|
|
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
|
-
|
|
52
|
+
response.row_id = info.lastInsertRowid;
|
|
53
|
+
response.success = true;
|
|
47
54
|
} catch (e) {
|
|
48
|
-
|
|
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,9 +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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
183
|
+
}
|
|
178
184
|
}
|
|
179
185
|
}
|
|
180
186
|
|
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
|
+
"version": "0.8.4",
|
|
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
|
-
|
|
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
|
|
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>
|
package/ui/js/doc.hornbill.js
CHANGED
|
@@ -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
|
-
|
|
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: {
|