hdoc-tools 0.17.11 → 0.17.13
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 +15 -15
- package/hdoc-build.js +2 -2
- package/hdoc-module.js +38 -21
- package/hdoc-serve.js +1 -1
- package/package.json +2 -2
- package/templates/pdf/css/hdocs-pdf.css +33 -0
package/hdoc-build-pdf.js
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
// Use cheerio to parse html
|
40
40
|
const $ = cheerio.load(html_source);
|
41
|
-
|
41
|
+
|
42
42
|
// Get iFrames from HTML, to replace with a tags
|
43
43
|
let iframes = [];
|
44
44
|
const iframe_html = $('iframe').map(function () {
|
@@ -55,7 +55,7 @@
|
|
55
55
|
const regex = new RegExp(`<iframe.*src="${iframes[i].src.replace('/', '\\/')}".*</iframe>`);
|
56
56
|
html_source = html_source.replace(regex, link);
|
57
57
|
}
|
58
|
-
|
58
|
+
|
59
59
|
// Get image links from HTML, to embed into the pdf
|
60
60
|
let imgs = [];
|
61
61
|
const srcs = $('img').map(function (i) {
|
@@ -64,18 +64,18 @@
|
|
64
64
|
imgs.push(...srcs);
|
65
65
|
for (let i = 0; i < imgs.length; i++) {
|
66
66
|
if (!hdoc.valid_url(imgs[i])) {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
67
|
+
// Internal link
|
68
|
+
const image_path = path.join(book_work_root, imgs[i].replace('_books/', ''));
|
69
|
+
try {
|
70
|
+
const image_buffer = fs.readFileSync(image_path);
|
71
|
+
const mime_type = mime.lookup(image_path);
|
72
|
+
let image_b64 = image_buffer.toString("base64");
|
73
|
+
image_b64 = `data:${mime_type};base64,${image_b64}`;
|
74
|
+
html_source = html_source.replace(imgs[i], image_b64);
|
75
|
+
} catch (err) {
|
76
|
+
console.log('Error reading image from HTML source [', image_path, '] -', err);
|
77
|
+
return null;
|
78
|
+
}
|
79
79
|
} else {
|
80
80
|
// External Link
|
81
81
|
try {
|
@@ -100,7 +100,7 @@
|
|
100
100
|
|
101
101
|
exports.generate_pdf = async function (browser, pdf_template_path, pdf_template_content, book_config, html_source, target_file, css_templates, verbose = false) {
|
102
102
|
let pdf_size = 0;
|
103
|
-
|
103
|
+
|
104
104
|
// Cache footer
|
105
105
|
if (footer === '') footer = get_footer(pdf_template_path);
|
106
106
|
|
package/hdoc-build.js
CHANGED
@@ -533,7 +533,7 @@
|
|
533
533
|
if (!bc[relative_path.replace('.html', '')] && bc[relative_path.replace('/index.html', '')]) {
|
534
534
|
relative_path = relative_path.replace('/index.html', '');
|
535
535
|
}
|
536
|
-
|
536
|
+
|
537
537
|
index_records.push({
|
538
538
|
relative_path: relative_path,
|
539
539
|
index_html: hdoc_index.transform_html_for_index(html_txt),
|
@@ -624,7 +624,7 @@
|
|
624
624
|
let last_commit_date = fm_headers[i].value;
|
625
625
|
if (last_commit_date !== 'No Commit Date Available') {
|
626
626
|
last_commit_date = new Date(fm_headers[i].value).toDateString();
|
627
|
-
}
|
627
|
+
}
|
628
628
|
wip_doc_header = wip_doc_header.replaceAll('{{last-update}}', last_commit_date);
|
629
629
|
break;
|
630
630
|
}
|
package/hdoc-module.js
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
const axios = require('axios'),
|
5
5
|
axiosRetry = require('axios-retry'),
|
6
6
|
cheerio = require('cheerio'),
|
7
|
+
fs = require('fs'),
|
7
8
|
html2text = require('html-to-text'),
|
8
9
|
https = require('https'),
|
9
10
|
htmlentities = require('html-entities'),
|
11
|
+
path = require('path'),
|
10
12
|
wordsCount = require('words-count').default;
|
11
13
|
|
12
14
|
let includesCache = {},
|
@@ -106,6 +108,7 @@
|
|
106
108
|
found: 0,
|
107
109
|
success: 0,
|
108
110
|
failed: 0,
|
111
|
+
included: [],
|
109
112
|
errors: []
|
110
113
|
};
|
111
114
|
|
@@ -136,30 +139,44 @@
|
|
136
139
|
}
|
137
140
|
|
138
141
|
// Validate link in INCLUDE
|
139
|
-
try {
|
140
|
-
new URL(link);
|
141
|
-
} catch (err) {
|
142
|
-
response.failed++;
|
143
|
-
response.errors.push(`Error validating INCLUDE link [${link}] from [${file_path}]: ${e}`);
|
144
|
-
continue;
|
145
|
-
}
|
146
|
-
|
147
142
|
let file_content;
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
143
|
+
if (link.startsWith('http://') || link.startsWith('https://')) {
|
144
|
+
// Remote content to include
|
145
|
+
try {
|
146
|
+
new URL(link);
|
147
|
+
} catch (e) {
|
148
|
+
response.failed++;
|
149
|
+
response.errors.push(`Error validating INCLUDE link [${link}] from [${file_path}]: ${e}`);
|
150
|
+
continue;
|
153
151
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
152
|
+
|
153
|
+
try {
|
154
|
+
const file_response = await axios.get(link);
|
155
|
+
if (retried) {
|
156
|
+
retried = false;
|
157
|
+
console.log(`API call retry success!`);
|
158
|
+
}
|
159
|
+
if (file_response.status === 200) {
|
160
|
+
file_content = file_response.data;
|
161
|
+
} else {
|
162
|
+
throw `Unexpected Status ${file_response.status}`;
|
163
|
+
}
|
164
|
+
} catch (e) {
|
165
|
+
response.failed++;
|
166
|
+
response.errors.push(`Error getting INCLUDE link content [${link}] from [${file_path}]: ${e}`);
|
167
|
+
continue;
|
158
168
|
}
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
169
|
+
console.log(`Included From Remote Source: ${link}`);
|
170
|
+
} else {
|
171
|
+
// Local content to include
|
172
|
+
try {
|
173
|
+
file_content = fs.readFileSync(path.join(process.cwd(), link), 'utf8');
|
174
|
+
} catch (e) {
|
175
|
+
response.failed++;
|
176
|
+
response.errors.push(`Error getting INCLUDE file [${link}] from [${file_path}]: ${e}`);
|
177
|
+
continue;
|
178
|
+
}
|
179
|
+
console.log(`Included From Local Source: ${link}`);
|
163
180
|
}
|
164
181
|
response.success++;
|
165
182
|
includesCache[link] = file_content;
|
package/hdoc-serve.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdoc-tools",
|
3
|
-
"version": "0.17.
|
3
|
+
"version": "0.17.13",
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
5
5
|
"main": "hdoc.js",
|
6
6
|
"bin": {
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"mime-types": "^2.1.35",
|
55
55
|
"multer": "^1.4.5-lts.1",
|
56
56
|
"prompt": "^1.3.0",
|
57
|
-
"puppeteer": "^
|
57
|
+
"puppeteer": "^21.11.0",
|
58
58
|
"retry": "^0.13.1",
|
59
59
|
"stream": "0.0.2",
|
60
60
|
"true-case-path": "^2.2.1",
|
@@ -451,4 +451,37 @@ video {
|
|
451
451
|
|
452
452
|
code {
|
453
453
|
font-size: 0.9em;
|
454
|
+
}
|
455
|
+
|
456
|
+
/* From Bootstrap 5, text color decorations */
|
457
|
+
.text-primary {
|
458
|
+
color: #0d6efd !important;
|
459
|
+
}
|
460
|
+
|
461
|
+
.text-secondary {
|
462
|
+
color: #6c757d !important;
|
463
|
+
}
|
464
|
+
|
465
|
+
.text-success {
|
466
|
+
color: #198754 !important;
|
467
|
+
}
|
468
|
+
|
469
|
+
.text-info {
|
470
|
+
color: #0dcaf0 !important;
|
471
|
+
}
|
472
|
+
|
473
|
+
.text-warning {
|
474
|
+
color: #ffc107 !important;
|
475
|
+
}
|
476
|
+
|
477
|
+
.text-danger {
|
478
|
+
color: #dc3545 !important;
|
479
|
+
}
|
480
|
+
|
481
|
+
.text-light {
|
482
|
+
color: #f8f9fa !important;
|
483
|
+
}
|
484
|
+
|
485
|
+
.text-dark {
|
486
|
+
color: #212529 !important;
|
454
487
|
}
|