hdoc-tools 0.45.1 → 0.47.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-pdf.js +7 -8
- package/hdoc-build.js +440 -626
- package/hdoc-create.js +1 -1
- package/hdoc-db.js +2 -24
- package/hdoc-init.js +34 -14
- package/hdoc-module.js +292 -79
- package/hdoc-serve.js +4 -6
- package/hdoc-stats.js +7 -12
- package/hdoc-validate.js +4 -6
- package/hdoc.js +3 -3
- package/npm-shrinkwrap.json +6921 -0
- package/package.json +12 -25
package/hdoc-build-pdf.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const axios = require("axios");
|
|
3
2
|
const cheerio = require("cheerio");
|
|
4
|
-
const fs = require("fs
|
|
5
|
-
const mime = require("mime-types");
|
|
3
|
+
const fs = require("node:fs");
|
|
6
4
|
const path = require("node:path");
|
|
7
5
|
const hdoc = require(path.join(__dirname, "hdoc-module.js"));
|
|
8
6
|
|
|
@@ -84,7 +82,10 @@
|
|
|
84
82
|
);
|
|
85
83
|
try {
|
|
86
84
|
const image_buffer = fs.readFileSync(image_path);
|
|
87
|
-
|
|
85
|
+
// Inline MIME type lookup for image formats commonly found in documentation.
|
|
86
|
+
// Falls back to application/octet-stream for any unrecognised extension so the
|
|
87
|
+
// base64 data URI is still well-formed even if the browser can't render it.
|
|
88
|
+
const mime_type = ({ '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.svg': 'image/svg+xml', '.webp': 'image/webp', '.bmp': 'image/bmp', '.ico': 'image/x-icon' })[path.extname(image_path).toLowerCase()] || 'application/octet-stream';
|
|
88
89
|
let image_b64 = image_buffer.toString("base64");
|
|
89
90
|
image_b64 = `data:${mime_type};base64,${image_b64}`;
|
|
90
91
|
processed_html_source = processed_html_source.replace(
|
|
@@ -103,11 +104,9 @@
|
|
|
103
104
|
} else {
|
|
104
105
|
// External Link
|
|
105
106
|
try {
|
|
106
|
-
const file_response = await
|
|
107
|
-
responseType: 'arraybuffer'
|
|
108
|
-
});
|
|
107
|
+
const file_response = await fetch(imgs[i]);
|
|
109
108
|
if (file_response.status === 200) {
|
|
110
|
-
let image_b64 = imageEncode(file_response.
|
|
109
|
+
let image_b64 = imageEncode(await file_response.arrayBuffer(), file_response.headers.get('content-type'));
|
|
111
110
|
|
|
112
111
|
|
|
113
112
|
const regexQ = `<img\\s+[^>]*src=["']${imgs[i].replaceAll('/', '\\/').replaceAll('.', '\\.')}["'][^>]*>`;
|