hdoc-tools 0.47.1 → 0.47.2
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 +1 -1
- package/hdoc-module.js +30 -79
- package/npm-shrinkwrap.json +0 -41
- package/package.json +1 -2
package/hdoc-build.js
CHANGED
|
@@ -1229,7 +1229,7 @@
|
|
|
1229
1229
|
for (let i = 0; i < md_files.length; i++) {
|
|
1230
1230
|
mdPromiseArray.push(md_files[i]);
|
|
1231
1231
|
}
|
|
1232
|
-
const chunkSize =
|
|
1232
|
+
const chunkSize = 3;
|
|
1233
1233
|
for (let i = 0; i < mdPromiseArray.length; i += chunkSize) {
|
|
1234
1234
|
const chunk = mdPromiseArray.slice(i, i + chunkSize);
|
|
1235
1235
|
// do whatever
|
package/hdoc-module.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const crypto = require("node:crypto");
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const os = require("node:os");
|
|
6
|
-
const { JSDOM } = require("jsdom");
|
|
7
6
|
const path = require("node:path");
|
|
8
7
|
|
|
9
8
|
const includesCache = {};
|
|
@@ -245,82 +244,37 @@
|
|
|
245
244
|
|
|
246
245
|
// Processes HTML, wraps h2 and h3 tags and their content in divs with an id matching that of the h text
|
|
247
246
|
exports.wrapHContent = (htmlContent) => {
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
currentH2Div.id = makeAnchorIdFriendly(node.textContent.trim());
|
|
270
|
-
currentH2Div.appendChild(node);
|
|
271
|
-
} else if (node.tagName.toLowerCase() === "h3") {
|
|
272
|
-
// When an <h3> is found, close the current <h3> div (if any) and start a new one
|
|
273
|
-
if (currentH3Div) {
|
|
274
|
-
if (currentH2Div) {
|
|
275
|
-
currentH2Div.appendChild(currentH3Div);
|
|
276
|
-
} else {
|
|
277
|
-
newContent.appendChild(currentH3Div);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
currentH3Div = document.createElement("div");
|
|
281
|
-
currentH3Div.id = makeAnchorIdFriendly(node.textContent.trim());
|
|
282
|
-
currentH3Div.appendChild(node);
|
|
283
|
-
} else {
|
|
284
|
-
if (currentH3Div) {
|
|
285
|
-
currentH3Div.appendChild(node);
|
|
286
|
-
} else if (currentH2Div) {
|
|
287
|
-
currentH2Div.appendChild(node);
|
|
288
|
-
} else {
|
|
289
|
-
newContent.appendChild(node);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
247
|
+
const $ = cheerio.load(htmlContent, { decodeEntities: false });
|
|
248
|
+
let result = '';
|
|
249
|
+
let inH2 = false;
|
|
250
|
+
let inH3 = false;
|
|
251
|
+
|
|
252
|
+
$('body').contents().each(function() {
|
|
253
|
+
const tagName = this.type === 'tag' ? this.name?.toLowerCase() : null;
|
|
254
|
+
|
|
255
|
+
if (tagName === 'h2') {
|
|
256
|
+
// Close open h3 (nested inside h2), then close h2
|
|
257
|
+
if (inH3) { result += '</div>'; inH3 = false; }
|
|
258
|
+
if (inH2) { result += '</div>'; inH2 = false; }
|
|
259
|
+
const anchorId = makeAnchorIdFriendly($(this).text().trim());
|
|
260
|
+
result += `<div id="${anchorId}">${$.html(this)}`;
|
|
261
|
+
inH2 = true;
|
|
262
|
+
} else if (tagName === 'h3') {
|
|
263
|
+
// Close previous h3 (it stays nested inside any open h2)
|
|
264
|
+
if (inH3) { result += '</div>'; inH3 = false; }
|
|
265
|
+
const anchorId = makeAnchorIdFriendly($(this).text().trim());
|
|
266
|
+
result += `<div id="${anchorId}">${$.html(this)}`;
|
|
267
|
+
inH3 = true;
|
|
292
268
|
} else {
|
|
293
|
-
|
|
294
|
-
currentH3Div.appendChild(node);
|
|
295
|
-
} else if (currentH2Div) {
|
|
296
|
-
currentH2Div.appendChild(node);
|
|
297
|
-
} else {
|
|
298
|
-
newContent.appendChild(node);
|
|
299
|
-
}
|
|
269
|
+
result += $.html(this);
|
|
300
270
|
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Append the last <h3> div if any
|
|
304
|
-
if (currentH3Div) {
|
|
305
|
-
if (currentH2Div) {
|
|
306
|
-
currentH2Div.appendChild(currentH3Div);
|
|
307
|
-
} else {
|
|
308
|
-
newContent.appendChild(currentH3Div);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Append the last <h2> div if any
|
|
313
|
-
if (currentH2Div) {
|
|
314
|
-
newContent.appendChild(currentH2Div);
|
|
315
|
-
}
|
|
271
|
+
});
|
|
316
272
|
|
|
317
|
-
//
|
|
318
|
-
|
|
319
|
-
|
|
273
|
+
// Flush remaining open divs — h3 is nested inside h2 so close inner first
|
|
274
|
+
if (inH3) result += '</div>';
|
|
275
|
+
if (inH2) result += '</div>';
|
|
320
276
|
|
|
321
|
-
|
|
322
|
-
const outputHtml = dom.serialize();
|
|
323
|
-
return outputHtml;
|
|
277
|
+
return `<html><head></head><body>${result}</body></html>`;
|
|
324
278
|
};
|
|
325
279
|
|
|
326
280
|
exports.getIDDivs = (html_body) => {
|
|
@@ -407,14 +361,11 @@
|
|
|
407
361
|
};
|
|
408
362
|
|
|
409
363
|
exports.html_to_text = (html, { baseElement } = {}) => {
|
|
410
|
-
const
|
|
411
|
-
const document = dom.window.document;
|
|
364
|
+
const $ = cheerio.load(html, { decodeEntities: false });
|
|
412
365
|
if (baseElement) {
|
|
413
|
-
return
|
|
414
|
-
.map((el) => el.textContent)
|
|
415
|
-
.join("\n");
|
|
366
|
+
return $(baseElement).map((_i, el) => $(el).text()).get().join("\n");
|
|
416
367
|
}
|
|
417
|
-
return
|
|
368
|
+
return $("body").text();
|
|
418
369
|
};
|
|
419
370
|
|
|
420
371
|
exports.get_html_read_time = (html) => {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"better-sqlite3": "12.8.0",
|
|
17
17
|
"cheerio": "1.2.0",
|
|
18
18
|
"express": "4.22.1",
|
|
19
|
-
"jsdom": "25.0.1",
|
|
20
19
|
"markdown-it": "14.1.1",
|
|
21
20
|
"markdown-it-container": "4.0.0",
|
|
22
21
|
"markdown-it-front-matter": "0.2.4",
|
|
@@ -3969,46 +3968,6 @@
|
|
|
3969
3968
|
"js-yaml": "bin/js-yaml.js"
|
|
3970
3969
|
}
|
|
3971
3970
|
},
|
|
3972
|
-
"node_modules/jsdom": {
|
|
3973
|
-
"version": "25.0.1",
|
|
3974
|
-
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-25.0.1.tgz",
|
|
3975
|
-
"integrity": "sha512-8i7LzZj7BF8uplX+ZyOlIz86V6TAsSs+np6m1kpW9u0JWi4z/1t+FzcK1aek+ybTnAC4KhBL4uXCNT0wcUIeCw==",
|
|
3976
|
-
"license": "MIT",
|
|
3977
|
-
"dependencies": {
|
|
3978
|
-
"cssstyle": "4.1.0",
|
|
3979
|
-
"data-urls": "5.0.0",
|
|
3980
|
-
"decimal.js": "10.4.3",
|
|
3981
|
-
"form-data": "4.0.0",
|
|
3982
|
-
"html-encoding-sniffer": "4.0.0",
|
|
3983
|
-
"http-proxy-agent": "7.0.2",
|
|
3984
|
-
"https-proxy-agent": "7.0.5",
|
|
3985
|
-
"is-potential-custom-element-name": "1.0.1",
|
|
3986
|
-
"nwsapi": "2.2.12",
|
|
3987
|
-
"parse5": "7.1.2",
|
|
3988
|
-
"rrweb-cssom": "0.7.1",
|
|
3989
|
-
"saxes": "6.0.0",
|
|
3990
|
-
"symbol-tree": "3.2.4",
|
|
3991
|
-
"tough-cookie": "5.0.0",
|
|
3992
|
-
"w3c-xmlserializer": "5.0.0",
|
|
3993
|
-
"webidl-conversions": "7.0.0",
|
|
3994
|
-
"whatwg-encoding": "3.1.1",
|
|
3995
|
-
"whatwg-mimetype": "4.0.0",
|
|
3996
|
-
"whatwg-url": "14.0.0",
|
|
3997
|
-
"ws": "8.18.0",
|
|
3998
|
-
"xml-name-validator": "5.0.0"
|
|
3999
|
-
},
|
|
4000
|
-
"engines": {
|
|
4001
|
-
"node": ">=18"
|
|
4002
|
-
},
|
|
4003
|
-
"peerDependencies": {
|
|
4004
|
-
"canvas": "2.11.2"
|
|
4005
|
-
},
|
|
4006
|
-
"peerDependenciesMeta": {
|
|
4007
|
-
"canvas": {
|
|
4008
|
-
"optional": true
|
|
4009
|
-
}
|
|
4010
|
-
}
|
|
4011
|
-
},
|
|
4012
3971
|
"node_modules/json-parse-even-better-errors": {
|
|
4013
3972
|
"version": "2.3.1",
|
|
4014
3973
|
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hdoc-tools",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.2",
|
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
|
5
5
|
"main": "hdoc.js",
|
|
6
6
|
"bin": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"better-sqlite3": "12.8.0",
|
|
44
44
|
"cheerio": "1.2.0",
|
|
45
45
|
"express": "4.22.1",
|
|
46
|
-
"jsdom": "25.0.1",
|
|
47
46
|
"markdown-it": "14.1.1",
|
|
48
47
|
"markdown-it-container": "4.0.0",
|
|
49
48
|
"markdown-it-front-matter": "0.2.4",
|