hdoc-tools 0.46.0 → 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 CHANGED
@@ -1,8 +1,6 @@
1
1
  (() => {
2
- const axios = require("axios");
3
2
  const cheerio = require("cheerio");
4
- const fs = require("fs-extra");
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
- const mime_type = mime.lookup(image_path);
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 axios.get(imgs[i], {
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.data, file_response.headers['content-type']);
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('.', '\\.')}["'][^>]*>`;