hdoc-tools 0.27.0 → 0.28.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.
Files changed (3) hide show
  1. package/hdoc-db.js +107 -97
  2. package/hdoc-help.js +6 -2
  3. package/package.json +1 -1
package/hdoc-db.js CHANGED
@@ -1,97 +1,107 @@
1
- (() => {
2
- const html2text = require("html-to-text");
3
- const path = require("node:path");
4
- const hdoc = require(path.join(__dirname, "hdoc-module.js"));
5
-
6
- exports.create_table = (db, table_name, columns, virtual, fts5) => {
7
- const create_sql = ["CREATE"];
8
- if (virtual) create_sql.push("VIRTUAL");
9
- create_sql.push("TABLE");
10
- create_sql.push(table_name);
11
- if (fts5) create_sql.push("USING fts5(");
12
- else create_sql.push("(");
13
- for (let i = 0; i < columns.length; i++) {
14
- if (i !== 0) create_sql.push(`,${columns[i]}`);
15
- else create_sql.push(columns[i]);
16
- }
17
- create_sql.push(");");
18
- try {
19
- db.exec(create_sql.join("\n"));
20
- return null;
21
- } catch (e) {
22
- return e;
23
- }
24
- };
25
-
26
- exports.insert_record = (db, table, columns, values) => {
27
- const response = {
28
- success: false,
29
- row_id: 0,
30
- error: null,
31
- };
32
- const queryProps = [];
33
- queryProps.push(`INSERT INTO ${table}`);
34
- let cols = "(";
35
- let vals = "VALUES (";
36
- for (let i = 0; i < columns.length; i++) {
37
- if (i === 0) {
38
- cols += `${columns[i].replace("UNINDEXED", "").replace("INTEGER", "").trim()}`;
39
- vals += "?";
40
- } else {
41
- cols += `, ${columns[i].replace("UNINDEXED", "").replace("INTEGER", "").trim()}`;
42
- vals += ", ?";
43
- }
44
- }
45
- cols += ")";
46
- vals += ")";
47
- queryProps.push(cols);
48
- queryProps.push(vals);
49
-
50
- try {
51
- const stmt = db.prepare(queryProps.join(" "));
52
- const info = stmt.run(values);
53
- response.row_id = info.lastInsertRowid;
54
- response.success = true;
55
- } catch (e) {
56
- response.error = e;
57
- }
58
- return response;
59
- };
60
-
61
- exports.transform_html_for_index = (html_txt) => {
62
- const response = {
63
- fm_props: {},
64
- sections: [],
65
- };
66
-
67
- // Get frontmatter properties
68
- const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
69
- response.fm_props = fm_headers.fm_properties;
70
-
71
- // Convert HTML into plain text
72
- response.text = html2text.convert(html_txt, {
73
- ignoreHref: true,
74
- ignoreImage: true,
75
- uppercaseHeadings: false,
76
- wordwrap: null,
77
- });
78
-
79
- // Convert HTML into preview text
80
- let preview = html2text.convert(html_txt, {
81
- baseElement: "p",
82
- ignoreHref: true,
83
- ignoreImage: true,
84
- uppercaseHeadings: false,
85
- wordwrap: null,
86
- });
87
- preview = hdoc
88
- .truncate_string(preview, 200, true)
89
- .replace(/(?:\r\n|\r|\n)/g, " ");
90
- response.sections.push({
91
- text: response.text,
92
- preview: preview,
93
- });
94
- //}
95
- return response;
96
- };
97
- })();
1
+ (() => {
2
+ const html2text = require("html-to-text");
3
+ const path = require("node:path");
4
+ const hdoc = require(path.join(__dirname, "hdoc-module.js"));
5
+
6
+ exports.create_table = (db, table_name, columns, virtual, fts5) => {
7
+ const create_sql = ["CREATE"];
8
+ if (virtual) create_sql.push("VIRTUAL");
9
+ create_sql.push("TABLE");
10
+ create_sql.push(table_name);
11
+ if (fts5) create_sql.push("USING fts5(");
12
+ else create_sql.push("(");
13
+ for (let i = 0; i < columns.length; i++) {
14
+ if (i !== 0) create_sql.push(`,${columns[i]}`);
15
+ else create_sql.push(columns[i]);
16
+ }
17
+ create_sql.push(");");
18
+ try {
19
+ db.exec(create_sql.join("\n"));
20
+ return null;
21
+ } catch (e) {
22
+ return e;
23
+ }
24
+ };
25
+
26
+ exports.insert_record = (db, table, columns, values) => {
27
+ const response = {
28
+ success: false,
29
+ row_id: 0,
30
+ error: null,
31
+ };
32
+ const queryProps = [];
33
+ queryProps.push(`INSERT INTO ${table}`);
34
+ let cols = "(";
35
+ let vals = "VALUES (";
36
+ for (let i = 0; i < columns.length; i++) {
37
+ if (i === 0) {
38
+ cols += `${columns[i].replace("UNINDEXED", "").replace("INTEGER", "").trim()}`;
39
+ vals += "?";
40
+ } else {
41
+ cols += `, ${columns[i].replace("UNINDEXED", "").replace("INTEGER", "").trim()}`;
42
+ vals += ", ?";
43
+ }
44
+ }
45
+ cols += ")";
46
+ vals += ")";
47
+ queryProps.push(cols);
48
+ queryProps.push(vals);
49
+
50
+ try {
51
+ const stmt = db.prepare(queryProps.join(" "));
52
+ const info = stmt.run(values);
53
+ response.row_id = info.lastInsertRowid;
54
+ response.success = true;
55
+ } catch (e) {
56
+ response.error = e;
57
+ }
58
+ return response;
59
+ };
60
+
61
+ exports.transform_html_for_index = (html_txt) => {
62
+ const response = {
63
+ fm_props: {},
64
+ sections: [],
65
+ };
66
+
67
+ // Get frontmatter properties
68
+ const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
69
+ response.fm_props = fm_headers.fm_properties;
70
+
71
+ // Convert HTML into plain text
72
+ response.text = html2text.convert(html_txt, {
73
+ ignoreHref: true,
74
+ ignoreImage: true,
75
+ uppercaseHeadings: false,
76
+ wordwrap: null,
77
+ selectors: [
78
+ { selector: 'h2', format: 'blockString' },
79
+ { selector: 'h3', format: 'blockString' },
80
+ { selector: 'h4', format: 'blockString' }
81
+ ]
82
+ });
83
+
84
+ // Convert HTML into preview text
85
+ let preview = html2text.convert(html_txt, {
86
+ baseElement: "p",
87
+ ignoreHref: true,
88
+ ignoreImage: true,
89
+ uppercaseHeadings: false,
90
+ wordwrap: null,
91
+ selectors: [
92
+ { selector: 'h2', format: 'blockString' },
93
+ { selector: 'h3', format: 'blockString' },
94
+ { selector: 'h4', format: 'blockString' }
95
+ ]
96
+ });
97
+ preview = hdoc
98
+ .truncate_string(preview, 200, true)
99
+ .replace(/(?:\r\n|\r|\n)/g, " ");
100
+ response.sections.push({
101
+ text: response.text,
102
+ preview: preview,
103
+ });
104
+ //}
105
+ return response;
106
+ };
107
+ })();
package/hdoc-help.js CHANGED
@@ -9,7 +9,9 @@ Command Line Usage
9
9
  Commands
10
10
 
11
11
  - build
12
- Performs a local build of the book, and outputs as a ZIP file. Use the '--set-version 1.2.3' argument to set the version number of the built book. Use the '--no-color' argument to remove any color control characters from the output.
12
+ Performs a local build of the book, and outputs as a ZIP file.
13
+ - Use the '--set-version 1.2.3' argument to set the version number of the built book.
14
+ - Use the '--no-color' argument to remove any color control characters from the output.
13
15
 
14
16
  - createDocs
15
17
  Creates folder structure and markdown documents as defined in the HDocBook navigation item links
@@ -28,7 +30,9 @@ Commands
28
30
  The book statistics do not include counts for any externally hosted content injected into the book content using the [[INCLUDE]] tags.
29
31
 
30
32
  - validate
31
- Validates the book content. Use the '--set-version 1.2.3' argument to set the version number of the built book. Use the '--no-color' argument to remove any color control characters from the output.
33
+ Validates the book content.
34
+ - Use the '--set-version 1.2.3' argument to set the version number of the built book.
35
+ - Use the '--no-color' argument to remove any color control characters from the output.
32
36
 
33
37
  - bump
34
38
  Updates the semantic version number of the current book. If no options are specified, then the default of patch is applied:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {