hdoc-tools 0.9.49 → 0.9.51

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-db.js CHANGED
@@ -1,95 +1,95 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const html2text = require('html-to-text'),
5
- path = require('path'),
6
- hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
-
8
- exports.create_table = function (db, table_name, columns, virtual, fts5) {
9
- let create_sql = ['CREATE'];
10
- if (virtual) create_sql.push('VIRTUAL');
11
- create_sql.push('TABLE');
12
- create_sql.push(table_name);
13
- if (fts5) create_sql.push('USING fts5(');
14
- else create_sql.push('(');
15
- for (let i = 0; i < columns.length; i++) {
16
- if (i !== 0) create_sql.push(`,${columns[i]}`);
17
- else create_sql.push(columns[i]);
18
- }
19
- create_sql.push(');');
20
- try {
21
- db.exec(create_sql.join('\n'));
22
- return null;
23
- } catch (e) {
24
- return e;
25
- }
26
- };
27
-
28
- exports.insert_record = function (db, table, columns, values) {
29
- let response = {
30
- success: false,
31
- row_id: 0,
32
- error: null
33
- };
34
- let queryProps = [];
35
- queryProps.push(`INSERT INTO ${table}`);
36
- let cols = '(';
37
- let vals = 'VALUES (';
38
- for (let i = 0; i < columns.length; i++) {
39
- if (i === 0) {
40
- cols += `${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
41
- vals += '?';
42
- } else {
43
- cols += `, ${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
44
- vals += ', ?';
45
- }
46
- }
47
- cols += ')';
48
- vals += ')';
49
- queryProps.push(cols);
50
- queryProps.push(vals);
51
-
52
- try {
53
- const stmt = db.prepare(queryProps.join(' '));
54
- const info = stmt.run(values);
55
- response.row_id = info.lastInsertRowid;
56
- response.success = true;
57
- } catch (e) {
58
- response.error = e;
59
- }
60
- return response;
61
- };
62
-
63
- exports.transform_html_for_index = function (html_txt) {
64
- let response = {
65
- text: '',
66
- preview: '',
67
- fm_props: {}
68
- };
69
-
70
- // Get frontmatter properties
71
- const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
72
- response.fm_props = fm_headers.fm_properties;
73
-
74
- // Convert HTML into plain text
75
- response.text = html2text.convert(html_txt, {
76
- ignoreHref: true,
77
- ignoreImage: true,
78
- uppercaseHeadings: false,
79
- wordwrap: null
80
- });
81
-
82
- // Convert HTML into preview text
83
- response.preview = html2text.convert(html_txt, {
84
- baseElement: 'p',
85
- ignoreHref: true,
86
- ignoreImage: true,
87
- uppercaseHeadings: false,
88
- wordwrap: null
89
- });
90
- response.preview = hdoc.truncate_string(response.preview, 200, true).replace(/(?:\r\n|\r|\n)/g, ' ');
91
- return response;
92
- };
93
-
94
-
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const html2text = require('html-to-text'),
5
+ path = require('path'),
6
+ hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
+
8
+ exports.create_table = function (db, table_name, columns, virtual, fts5) {
9
+ let create_sql = ['CREATE'];
10
+ if (virtual) create_sql.push('VIRTUAL');
11
+ create_sql.push('TABLE');
12
+ create_sql.push(table_name);
13
+ if (fts5) create_sql.push('USING fts5(');
14
+ else create_sql.push('(');
15
+ for (let i = 0; i < columns.length; i++) {
16
+ if (i !== 0) create_sql.push(`,${columns[i]}`);
17
+ else create_sql.push(columns[i]);
18
+ }
19
+ create_sql.push(');');
20
+ try {
21
+ db.exec(create_sql.join('\n'));
22
+ return null;
23
+ } catch (e) {
24
+ return e;
25
+ }
26
+ };
27
+
28
+ exports.insert_record = function (db, table, columns, values) {
29
+ let response = {
30
+ success: false,
31
+ row_id: 0,
32
+ error: null
33
+ };
34
+ let queryProps = [];
35
+ queryProps.push(`INSERT INTO ${table}`);
36
+ let cols = '(';
37
+ let vals = 'VALUES (';
38
+ for (let i = 0; i < columns.length; i++) {
39
+ if (i === 0) {
40
+ cols += `${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
41
+ vals += '?';
42
+ } else {
43
+ cols += `, ${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
44
+ vals += ', ?';
45
+ }
46
+ }
47
+ cols += ')';
48
+ vals += ')';
49
+ queryProps.push(cols);
50
+ queryProps.push(vals);
51
+
52
+ try {
53
+ const stmt = db.prepare(queryProps.join(' '));
54
+ const info = stmt.run(values);
55
+ response.row_id = info.lastInsertRowid;
56
+ response.success = true;
57
+ } catch (e) {
58
+ response.error = e;
59
+ }
60
+ return response;
61
+ };
62
+
63
+ exports.transform_html_for_index = function (html_txt) {
64
+ let response = {
65
+ text: '',
66
+ preview: '',
67
+ fm_props: {}
68
+ };
69
+
70
+ // Get frontmatter properties
71
+ const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
72
+ response.fm_props = fm_headers.fm_properties;
73
+
74
+ // Convert HTML into plain text
75
+ response.text = html2text.convert(html_txt, {
76
+ ignoreHref: true,
77
+ ignoreImage: true,
78
+ uppercaseHeadings: false,
79
+ wordwrap: null
80
+ });
81
+
82
+ // Convert HTML into preview text
83
+ response.preview = html2text.convert(html_txt, {
84
+ baseElement: 'p',
85
+ ignoreHref: true,
86
+ ignoreImage: true,
87
+ uppercaseHeadings: false,
88
+ wordwrap: null
89
+ });
90
+ response.preview = hdoc.truncate_string(response.preview, 200, true).replace(/(?:\r\n|\r|\n)/g, ' ');
91
+ return response;
92
+ };
93
+
94
+
95
95
  })();
package/hdoc-help.js CHANGED
@@ -1,41 +1,41 @@
1
- (function () {
2
- 'use strict';
3
-
4
- exports.run = function() {
5
-
6
- // STEVE: The purpose of this function is to output information about hdoc arguments
7
- const helpText = `
8
- Command Line Usage
9
-
10
- hdoc <command> [switches]
11
-
12
- Commands
13
-
14
- - build
15
- Performs a local build of the book, and outputs as a ZIP file. Use non-mandatory argument '--set-version 1.2.3' to set the version number of the built book
16
-
17
- - createDocs
18
- Creates folder structure and markdown documents as defined in the HDocBook navigation item links
19
-
20
- - help
21
- Outputs available arguments and switches
22
-
23
- - init
24
- Initializes a new HDocBook project from a template, using runtime input variables
25
-
26
- - serve
27
- Starts a local web server on port 3000, serving the content. Supports a -port N to use a different port
28
-
29
- - stats
30
- Returns statistics regarding the book you are working on. Supports a -v switch for verbose output
31
-
32
- - validate
33
- Validates the book content
34
-
35
- Example
36
-
37
- hdoc stats -v
38
- `;
39
- console.log(helpText);
40
- };
1
+ (function () {
2
+ 'use strict';
3
+
4
+ exports.run = function() {
5
+
6
+ // STEVE: The purpose of this function is to output information about hdoc arguments
7
+ const helpText = `
8
+ Command Line Usage
9
+
10
+ hdoc <command> [switches]
11
+
12
+ Commands
13
+
14
+ - build
15
+ Performs a local build of the book, and outputs as a ZIP file. Use non-mandatory argument '--set-version 1.2.3' to set the version number of the built book
16
+
17
+ - createDocs
18
+ Creates folder structure and markdown documents as defined in the HDocBook navigation item links
19
+
20
+ - help
21
+ Outputs available arguments and switches
22
+
23
+ - init
24
+ Initializes a new HDocBook project from a template, using runtime input variables
25
+
26
+ - serve
27
+ Starts a local web server on port 3000, serving the content. Supports a -port N to use a different port
28
+
29
+ - stats
30
+ Returns statistics regarding the book you are working on. Supports a -v switch for verbose output
31
+
32
+ - validate
33
+ Validates the book content
34
+
35
+ Example
36
+
37
+ hdoc stats -v
38
+ `;
39
+ console.log(helpText);
40
+ };
41
41
  })();