hdoc-tools 0.59.0 → 0.60.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.
package/hdoc-build-db.js CHANGED
@@ -17,6 +17,10 @@
17
17
  "doc_lastmod",
18
18
  "doc_status",
19
19
  "doc_keywords",
20
+ // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
21
+ "doc_type UNINDEXED",
22
+ // Raw markdown source of the document (HTML sources are converted)
23
+ "doc_md UNINDEXED",
20
24
  ],
21
25
  hdoc_meta: [
22
26
  "resource_url",
@@ -148,6 +152,14 @@
148
152
 
149
153
  if (!book_config.tags) book_config.tags = [];
150
154
 
155
+ // Book-level content type from hdocbook.json bookType:
156
+ // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
157
+ // Bound as BigInt: better-sqlite3 binds JS numbers as REAL, and FTS5
158
+ // columns have no affinity to coerce them back to INTEGER
159
+ const book_doc_type = BigInt(
160
+ Number.isInteger(book_config.bookType) ? book_config.bookType : 0,
161
+ );
162
+
151
163
  // Build a prepared statement from a schema entry once, reusing it for every row.
152
164
  // Previously insert_record() called db.prepare() on every single insert.
153
165
  const make_stmt = (table) => {
@@ -193,6 +205,8 @@
193
205
  file.lastmod,
194
206
  file.status,
195
207
  file.keywords,
208
+ book_doc_type,
209
+ file.doc_md ?? "",
196
210
  );
197
211
  inserted_row_id = info.lastInsertRowid;
198
212
  } catch (e) {
package/hdoc-build.js CHANGED
@@ -14,6 +14,16 @@
14
14
  const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
15
15
  const hdoc_mermaid = require(path.join(__dirname, "hdoc-mermaid.js"));
16
16
  const archiver = require("archiver");
17
+ const TurndownService = require("turndown");
18
+ const turndown_gfm = require("turndown-plugin-gfm");
19
+
20
+ // HTML -> Markdown converter, used to populate the doc_md index column for
21
+ // static HTML sources (markdown sources store their raw markdown directly).
22
+ const turndown = new TurndownService({
23
+ headingStyle: "atx",
24
+ codeBlockStyle: "fenced",
25
+ });
26
+ turndown.use(turndown_gfm.gfm);
17
27
 
18
28
  const h_tags_to_search = ["h1", "h2", "h3"];
19
29
  const image_extensions = ["png", "svg", "jpg"];
@@ -268,6 +278,7 @@
268
278
  const fm_headers = [];
269
279
  let doc_title = "";
270
280
  let doc_type = "Article";
281
+ let doc_md = "";
271
282
  let fm_status = false;
272
283
  // Used only for static HTML: tracks whether the source file already had a
273
284
  // frontmatter comment block that needs replacing in the output.
@@ -296,6 +307,10 @@
296
307
  }
297
308
  }
298
309
 
310
+ // Raw markdown for the doc_md index column: full post-include content,
311
+ // minus the YAML frontmatter block.
312
+ doc_md = md_txt.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim();
313
+
299
314
  // Point the shared md instance at the current file before rendering
300
315
  // so the highlight callback logs and reports against the right path.
301
316
  currentMdFilePath = file_path;
@@ -411,6 +426,15 @@
411
426
  html_txt = fs.readFileSync(file_path.path, "utf8");
412
427
  html_txt = html_txt.replace(/\r/gm, ""); // Remove CR's so we're just dealing with newlines
413
428
 
429
+ // Best-guess markdown conversion of the HTML source for the doc_md
430
+ // index column (turndown drops the frontmatter comment automatically)
431
+ try {
432
+ doc_md = turndown.turndown(html_txt).trim();
433
+ } catch (e) {
434
+ console.error(`[WARNING] HTML to Markdown conversion failed for ${file_path.relativePath}: ${e}`);
435
+ doc_md = "";
436
+ }
437
+
414
438
  // Check if we have a frontmatter comment
415
439
  html_fm = hdoc.getHTMLFrontmatterHeader(html_txt);
416
440
 
@@ -798,6 +822,7 @@
798
822
  inline: inline_content,
799
823
  status: index_data.fm_props.status ? index_data.fm_props.status : 'release',
800
824
  keywords: index_data.fm_props.keywords ? index_data.fm_props.keywords : '',
825
+ doc_md: doc_md,
801
826
  });
802
827
  }
803
828
 
@@ -6,6 +6,7 @@
6
6
  const hdocbook_schema = require(path.join(__dirname, "schemas", "hdocbook.schema.json"));
7
7
  const valid_audience = hdocbook_schema.properties.audience.items.enum;
8
8
  const valid_product_families = hdocbook_schema.properties.productFamily.enum;
9
+ const valid_book_types = hdocbook_schema.properties.bookType.enum;
9
10
 
10
11
  const project_schema = require(path.join(__dirname, "schemas", "hdocbook-project.schema.json"));
11
12
  const project_top_keys = Object.keys(project_schema.properties);
@@ -192,7 +193,7 @@
192
193
  const file = 'hdocbook.json';
193
194
 
194
195
  check_extra_keys(config,
195
- ['docId', 'title', 'description', 'publicSource', 'version', 'productFamily',
196
+ ['docId', 'title', 'description', 'publicSource', 'version', 'productFamily', 'bookType',
196
197
  'coverImage', 'tags', 'audience', 'languages', 'readingTime', 'navigation', 'inline'],
197
198
  '', file, errors);
198
199
 
@@ -267,6 +268,10 @@
267
268
  }
268
269
  }
269
270
 
271
+ if (config.bookType !== undefined && !valid_book_types.includes(config.bookType)) {
272
+ errors.push(`${file}: "bookType" must be an integer, one of: ${valid_book_types.join(', ')} (0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref)`);
273
+ }
274
+
270
275
  if (config.coverImage !== undefined && typeof config.coverImage !== 'string') {
271
276
  errors.push(`${file}: "coverImage" must be a string`);
272
277
  }
@@ -22,7 +22,9 @@
22
22
  "markdown-it-container": "4.0.0",
23
23
  "markdown-it-front-matter": "0.2.4",
24
24
  "mermaid": "11.15.0",
25
- "puppeteer": "25.1.0"
25
+ "puppeteer": "25.1.0",
26
+ "turndown": "7.2.1",
27
+ "turndown-plugin-gfm": "1.0.2"
26
28
  },
27
29
  "bin": {
28
30
  "hdoc": "hdoc.js"
@@ -600,6 +602,12 @@
600
602
  "@chevrotain/types": "~11.1.1"
601
603
  }
602
604
  },
605
+ "node_modules/@mixmark-io/domino": {
606
+ "version": "2.2.0",
607
+ "resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz",
608
+ "integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==",
609
+ "license": "BSD-2-Clause"
610
+ },
603
611
  "node_modules/@protobufjs/aspromise": {
604
612
  "version": "1.1.2",
605
613
  "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
@@ -4413,6 +4421,21 @@
4413
4421
  "node": "*"
4414
4422
  }
4415
4423
  },
4424
+ "node_modules/turndown": {
4425
+ "version": "7.2.1",
4426
+ "resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.1.tgz",
4427
+ "integrity": "sha512-7YiPJw6rLClQL3oUKN3KgMaXeJJ2lAyZItclgKDurqnH61so4k4IH/qwmMva0zpuJc/FhRExBBnk7EbeFANlgQ==",
4428
+ "license": "MIT",
4429
+ "dependencies": {
4430
+ "@mixmark-io/domino": "^2.2.0"
4431
+ }
4432
+ },
4433
+ "node_modules/turndown-plugin-gfm": {
4434
+ "version": "1.0.2",
4435
+ "resolved": "https://registry.npmjs.org/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz",
4436
+ "integrity": "sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg==",
4437
+ "license": "MIT"
4438
+ },
4416
4439
  "node_modules/type-fest": {
4417
4440
  "version": "0.13.1",
4418
4441
  "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -61,6 +61,8 @@
61
61
  "markdown-it-container": "4.0.0",
62
62
  "markdown-it-front-matter": "0.2.4",
63
63
  "mermaid": "11.15.0",
64
- "puppeteer": "25.1.0"
64
+ "puppeteer": "25.1.0",
65
+ "turndown": "7.2.1",
66
+ "turndown-plugin-gfm": "1.0.2"
65
67
  }
66
68
  }
@@ -50,6 +50,11 @@
50
50
  "hdocs"
51
51
  ]
52
52
  },
53
+ "bookType": {
54
+ "type": "integer",
55
+ "description": "The type of content this book contains: 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref. Defaults to 0 when omitted.",
56
+ "enum": [0, 1, 2, 3, 4]
57
+ },
53
58
  "coverImage": {
54
59
  "type": "string",
55
60
  "description": "Root-relative path to a cover image used for gallery and social sharing. Optional."
@@ -4,6 +4,7 @@
4
4
  "description": "--description--",
5
5
  "publicSource": "--publicSource--",
6
6
  "productFamily": "hdocs",
7
+ "bookType": 0,
7
8
  "version": "0.0.1",
8
9
  "audience": [
9
10
  "public"