spec-up-t 1.2.5 → 1.2.6
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/assets/compiled/body.js +9 -9
- package/assets/compiled/head.css +6 -5
- package/assets/css/collapse-definitions.css +41 -0
- package/assets/css/create-pdf.css +339 -0
- package/assets/css/horizontal-scroll-hint.css +6 -0
- package/assets/css/image-full-size.css +1 -5
- package/assets/css/index.css +5 -0
- package/assets/css/search.css +8 -8
- package/assets/css/terms-and-definitions.css +3 -3
- package/assets/js/add-bootstrap-classes-to-images.js +2 -5
- package/assets/js/collapse-definitions.js +259 -34
- package/assets/js/collapse-meta-info.js +37 -10
- package/assets/js/collapsibleMenu.js +0 -24
- package/assets/js/create-term-filter.js +36 -18
- package/assets/js/hide-show-utility-container.js +0 -1
- package/assets/js/horizontal-scroll-hint.js +2 -2
- package/assets/js/image-full-size.js +0 -2
- package/assets/js/insert-trefs.js +135 -49
- package/assets/js/search.js +34 -20
- package/{src → config}/asset-map.json +1 -0
- package/gulpfile.js +1 -1
- package/index.js +3 -3
- package/package.json +1 -1
- package/src/collectExternalReferences/fetchTermsFromIndex.1.js +340 -0
- package/src/collectExternalReferences/fetchTermsFromIndex.js +1 -1
- package/src/collectExternalReferences/processXTrefsData.js +1 -1
- package/src/create-pdf.js +330 -21
- package/src/markdown-it-extensions.js +2 -2
- package/assets/css/pdf-styles.css +0 -170
- /package/{src/config → config}/paths.js +0 -0
package/src/create-pdf.js
CHANGED
|
@@ -29,7 +29,7 @@ const pdfLib = require('pdf-lib');
|
|
|
29
29
|
let bootstrapCss = bootstrapExists ? fs.readFileSync(bootstrapCssPath, 'utf8') : '';
|
|
30
30
|
|
|
31
31
|
// Path to PDF styles CSS
|
|
32
|
-
const pdfStylesPath = path.resolve(process.cwd(), 'assets/css/pdf
|
|
32
|
+
const pdfStylesPath = path.resolve(process.cwd(), 'assets/css/create-pdf.css');
|
|
33
33
|
const pdfStylesExist = fs.existsSync(pdfStylesPath);
|
|
34
34
|
const pdfStylesCss = pdfStylesExist ? fs.readFileSync(pdfStylesPath, 'utf8') : '';
|
|
35
35
|
|
|
@@ -38,8 +38,14 @@ const pdfLib = require('pdf-lib');
|
|
|
38
38
|
|
|
39
39
|
// Clean up unnecessary elements but be careful not to remove styles we need
|
|
40
40
|
await page.evaluate(() => {
|
|
41
|
-
|
|
41
|
+
// Preserve TOC if it exists (skip removing it even if it has display:none)
|
|
42
|
+
document.querySelectorAll('[style*="display: none"]:not(#toc):not(#toc *), .d-print-none:not(#toc):not(#toc *), script').forEach(element => element.remove());
|
|
42
43
|
// Don't remove all style elements as some might be important
|
|
44
|
+
|
|
45
|
+
// If TOC doesn't exist, we'll need to create one
|
|
46
|
+
if (!document.getElementById('toc')) {
|
|
47
|
+
console.log('No TOC found in the document. Will create one.');
|
|
48
|
+
}
|
|
43
49
|
});
|
|
44
50
|
|
|
45
51
|
// Handle dynamically fetched cross-reference terms
|
|
@@ -68,7 +74,7 @@ const pdfLib = require('pdf-lib');
|
|
|
68
74
|
container.style.margin = '0 auto';
|
|
69
75
|
container.style.padding = '0';
|
|
70
76
|
});
|
|
71
|
-
|
|
77
|
+
|
|
72
78
|
// Override any Bootstrap column constraints
|
|
73
79
|
const columns = document.querySelectorAll('[class*="col-"]');
|
|
74
80
|
columns.forEach(col => {
|
|
@@ -77,7 +83,7 @@ const pdfLib = require('pdf-lib');
|
|
|
77
83
|
col.style.paddingLeft = '0';
|
|
78
84
|
col.style.paddingRight = '0';
|
|
79
85
|
});
|
|
80
|
-
|
|
86
|
+
|
|
81
87
|
// Ensure body takes full width
|
|
82
88
|
document.body.style.maxWidth = '100%';
|
|
83
89
|
document.body.style.width = '100%';
|
|
@@ -113,18 +119,18 @@ const pdfLib = require('pdf-lib');
|
|
|
113
119
|
document.querySelectorAll('table').forEach(table => {
|
|
114
120
|
table.classList.add('table', 'table-bordered', 'table-striped', 'table-hover');
|
|
115
121
|
});
|
|
116
|
-
|
|
122
|
+
|
|
117
123
|
// Make sure meta-info is visible and toggle buttons are hidden
|
|
118
124
|
document.querySelectorAll('.meta-info, .term-meta').forEach(meta => {
|
|
119
125
|
meta.style.display = 'block';
|
|
120
126
|
});
|
|
121
|
-
|
|
127
|
+
|
|
122
128
|
document.querySelectorAll('.meta-toggle, button.meta-toggle').forEach(button => {
|
|
123
129
|
button.style.display = 'none';
|
|
124
130
|
});
|
|
125
131
|
});
|
|
126
132
|
|
|
127
|
-
// Inject logo, title, and description
|
|
133
|
+
// Inject logo, title, and description AND handle TOC creation if needed
|
|
128
134
|
await page.evaluate((logo, logoLink, title, description) => {
|
|
129
135
|
const titleWrapper = document.createElement('div');
|
|
130
136
|
titleWrapper.className = 'text-center mb-5 pb-4 border-bottom';
|
|
@@ -155,9 +161,88 @@ const pdfLib = require('pdf-lib');
|
|
|
155
161
|
}
|
|
156
162
|
|
|
157
163
|
document.body.insertBefore(titleWrapper, document.body.firstChild);
|
|
164
|
+
|
|
165
|
+
// Create a Table of Contents if it doesn't exist
|
|
166
|
+
if (!document.getElementById('toc')) {
|
|
167
|
+
// Generate a TOC based on the headings in the document
|
|
168
|
+
const headings = Array.from(document.querySelectorAll('h1:not(.pdf-title), h2, h3, h4, h5, h6')).filter(h => {
|
|
169
|
+
// Only include headings with IDs that can be linked to
|
|
170
|
+
return h.id && h.id.trim() !== '';
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (headings.length > 0) {
|
|
174
|
+
// Create TOC container
|
|
175
|
+
const tocContainer = document.createElement('div');
|
|
176
|
+
tocContainer.id = 'toc';
|
|
177
|
+
tocContainer.className = 'toc-container';
|
|
178
|
+
|
|
179
|
+
// Create TOC heading
|
|
180
|
+
const tocHeading = document.createElement('h2');
|
|
181
|
+
tocHeading.textContent = 'Contents';
|
|
182
|
+
tocHeading.className = 'toc-heading';
|
|
183
|
+
tocContainer.appendChild(tocHeading);
|
|
184
|
+
|
|
185
|
+
// Create TOC list
|
|
186
|
+
const tocList = document.createElement('ul');
|
|
187
|
+
tocList.className = 'toc-list';
|
|
188
|
+
tocContainer.appendChild(tocList);
|
|
189
|
+
|
|
190
|
+
// Add all headings to the TOC
|
|
191
|
+
let currentLevel = 0;
|
|
192
|
+
let currentList = tocList;
|
|
193
|
+
let listStack = [tocList];
|
|
194
|
+
|
|
195
|
+
headings.forEach(heading => {
|
|
196
|
+
// Get heading level (1-6 for h1-h6)
|
|
197
|
+
const level = parseInt(heading.tagName[1]);
|
|
198
|
+
|
|
199
|
+
// Navigate to the correct nesting level
|
|
200
|
+
if (level > currentLevel) {
|
|
201
|
+
// Go deeper - create a new nested list
|
|
202
|
+
for (let i = currentLevel; i < level; i++) {
|
|
203
|
+
if (currentList.lastChild) {
|
|
204
|
+
const nestedList = document.createElement('ul');
|
|
205
|
+
currentList.lastChild.appendChild(nestedList);
|
|
206
|
+
listStack.push(nestedList);
|
|
207
|
+
currentList = nestedList;
|
|
208
|
+
} else {
|
|
209
|
+
// If no items exist yet, add a dummy item
|
|
210
|
+
const dummyItem = document.createElement('li');
|
|
211
|
+
const nestedList = document.createElement('ul');
|
|
212
|
+
dummyItem.appendChild(nestedList);
|
|
213
|
+
currentList.appendChild(dummyItem);
|
|
214
|
+
listStack.push(nestedList);
|
|
215
|
+
currentList = nestedList;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} else if (level < currentLevel) {
|
|
219
|
+
// Go up - pop from the stack
|
|
220
|
+
for (let i = currentLevel; i > level; i--) {
|
|
221
|
+
listStack.pop();
|
|
222
|
+
}
|
|
223
|
+
currentList = listStack[listStack.length - 1];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
currentLevel = level;
|
|
227
|
+
|
|
228
|
+
// Create list item with link
|
|
229
|
+
const listItem = document.createElement('li');
|
|
230
|
+
const link = document.createElement('a');
|
|
231
|
+
link.href = '#' + heading.id;
|
|
232
|
+
link.textContent = heading.textContent;
|
|
233
|
+
listItem.appendChild(link);
|
|
234
|
+
currentList.appendChild(listItem);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Insert the TOC after the title section
|
|
238
|
+
document.body.insertBefore(tocContainer, titleWrapper.nextSibling);
|
|
239
|
+
|
|
240
|
+
console.log('Generated a Table of Contents with ' + headings.length + ' entries.');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
158
243
|
}, logo, logoLink, title, description);
|
|
159
|
-
|
|
160
|
-
// Direct manipulation of definition lists to ensure proper styling in PDF
|
|
244
|
+
|
|
245
|
+
// Direct manipulation of definition lists and TOC to ensure proper styling in PDF
|
|
161
246
|
await page.evaluate(() => {
|
|
162
247
|
// Process all definition lists
|
|
163
248
|
const definitionLists = document.querySelectorAll('dl.terms-and-definitions-list');
|
|
@@ -168,7 +253,7 @@ const pdfLib = require('pdf-lib');
|
|
|
168
253
|
// Remove background and borders with !important to override any existing styles
|
|
169
254
|
term.setAttribute('style', term.getAttribute('style') + '; background: transparent !important; background-color: transparent !important; background-image: none !important; border: none !important; border-radius: 0 !important; padding: 0.5rem 0 !important;');
|
|
170
255
|
});
|
|
171
|
-
|
|
256
|
+
|
|
172
257
|
// Ensure all meta-info content is visible
|
|
173
258
|
const metaInfoContents = list.querySelectorAll('dd.meta-info-content-wrapper');
|
|
174
259
|
metaInfoContents.forEach(content => {
|
|
@@ -179,42 +264,266 @@ const pdfLib = require('pdf-lib');
|
|
|
179
264
|
content.style.padding = '0.5rem 0';
|
|
180
265
|
content.style.margin = '0';
|
|
181
266
|
content.style.lineHeight = 'normal';
|
|
182
|
-
|
|
267
|
+
|
|
183
268
|
// Remove the collapsed class if present
|
|
184
269
|
content.classList.remove('collapsed');
|
|
185
270
|
});
|
|
186
|
-
|
|
271
|
+
|
|
187
272
|
// Hide all meta-info toggle buttons
|
|
188
273
|
const toggleButtons = list.querySelectorAll('.meta-info-toggle-button');
|
|
189
274
|
toggleButtons.forEach(button => {
|
|
190
275
|
button.style.display = 'none';
|
|
191
276
|
});
|
|
192
277
|
});
|
|
193
|
-
|
|
278
|
+
|
|
194
279
|
// Special handling for ALL transcluded terms with blue background - no class restrictions
|
|
195
280
|
document.querySelectorAll('.transcluded-xref-term').forEach(el => {
|
|
196
281
|
// Use the most aggressive approach possible to override the blue background
|
|
197
282
|
el.setAttribute('style', el.getAttribute('style') + '; background: transparent !important; background-color: transparent !important; background-image: none !important;');
|
|
198
|
-
|
|
283
|
+
|
|
199
284
|
// Also process any child elements to ensure complete removal of background
|
|
200
285
|
Array.from(el.children).forEach(child => {
|
|
201
286
|
child.setAttribute('style', child.getAttribute('style') + '; background: transparent !important; background-color: transparent !important; background-image: none !important;');
|
|
202
287
|
});
|
|
203
288
|
});
|
|
204
|
-
|
|
289
|
+
|
|
205
290
|
// Remove any inline styles that might be setting backgrounds
|
|
206
291
|
document.querySelectorAll('style').forEach(styleTag => {
|
|
207
292
|
let cssText = styleTag.textContent;
|
|
208
293
|
// If the style tag contains transcluded-xref-term styles, modify them
|
|
209
294
|
if (cssText.includes('transcluded-xref-term') && cssText.includes('background')) {
|
|
210
|
-
cssText = cssText.replace(/dt\.transcluded-xref-term[^}]+}/g,
|
|
211
|
-
|
|
295
|
+
cssText = cssText.replace(/dt\.transcluded-xref-term[^}]+}/g,
|
|
296
|
+
'dt.transcluded-xref-term, dd.transcluded-xref-term { background: transparent !important; background-color: transparent !important; background-image: none !important; }');
|
|
212
297
|
styleTag.textContent = cssText;
|
|
213
298
|
}
|
|
214
|
-
});
|
|
299
|
+
}); // Format Table of Contents for book-like layout
|
|
300
|
+
const toc = document.getElementById('toc');
|
|
301
|
+
if (toc) {
|
|
302
|
+
// Make sure TOC is visible
|
|
303
|
+
toc.style.display = 'block';
|
|
304
|
+
toc.style.visibility = 'visible';
|
|
305
|
+
toc.style.opacity = '1';
|
|
306
|
+
|
|
307
|
+
// Create a new TOC div for the PDF using a completely different approach
|
|
308
|
+
const pdfToc = document.createElement('div');
|
|
309
|
+
pdfToc.id = 'pdf-toc';
|
|
310
|
+
|
|
311
|
+
// Ensure TOC has a header
|
|
312
|
+
const tocHeading = document.createElement('h2');
|
|
313
|
+
tocHeading.textContent = 'Contents';
|
|
314
|
+
tocHeading.style.textAlign = 'center';
|
|
315
|
+
tocHeading.style.fontWeight = 'bold';
|
|
316
|
+
tocHeading.style.marginBottom = '1.5rem';
|
|
317
|
+
tocHeading.style.paddingBottom = '0.5rem';
|
|
318
|
+
tocHeading.style.borderBottom = '1px solid #000';
|
|
319
|
+
pdfToc.appendChild(tocHeading);
|
|
320
|
+
|
|
321
|
+
// Create a fresh TOC structure - completely rebuilding it
|
|
322
|
+
const tocList = document.createElement('ul');
|
|
323
|
+
tocList.style.listStyleType = 'none';
|
|
324
|
+
tocList.style.padding = '0';
|
|
325
|
+
tocList.style.margin = '0';
|
|
326
|
+
pdfToc.appendChild(tocList);
|
|
327
|
+
|
|
328
|
+
// Find all section headings to include in the TOC
|
|
329
|
+
// Look for both original TOC entries and also scan document headings
|
|
330
|
+
const tocOriginalLinks = toc.querySelectorAll('a');
|
|
331
|
+
|
|
332
|
+
// Process each TOC link to create a new TOC item
|
|
333
|
+
tocOriginalLinks.forEach((link, index) => {
|
|
334
|
+
const li = document.createElement('li');
|
|
335
|
+
const rowDiv = document.createElement('div');
|
|
336
|
+
rowDiv.className = 'toc-row';
|
|
337
|
+
|
|
338
|
+
const title = document.createElement('a');
|
|
339
|
+
title.href = link.getAttribute('href');
|
|
340
|
+
title.textContent = link.textContent;
|
|
341
|
+
title.className = 'toc-title';
|
|
342
|
+
title.setAttribute('data-target-id', link.getAttribute('href').substring(1)); // Store the target id
|
|
343
|
+
// Ensure no blue color or underline for TOC links
|
|
344
|
+
title.style.color = '#000';
|
|
345
|
+
title.style.textDecoration = 'none';
|
|
346
|
+
title.style.borderBottom = 'none';
|
|
347
|
+
title.style.backgroundColor = 'transparent';
|
|
348
|
+
|
|
349
|
+
const leader = document.createElement('div');
|
|
350
|
+
leader.className = 'toc-leader';
|
|
351
|
+
|
|
352
|
+
// Create page number placeholder - we'll fill in actual page numbers later
|
|
353
|
+
const pageNumber = document.createElement('span');
|
|
354
|
+
pageNumber.className = 'toc-page-number';
|
|
355
|
+
pageNumber.textContent = ''; // Empty for now
|
|
356
|
+
pageNumber.setAttribute('data-for-id', link.getAttribute('href').substring(1));
|
|
357
|
+
pageNumber.style.position = 'absolute';
|
|
358
|
+
pageNumber.style.right = '0';
|
|
359
|
+
|
|
360
|
+
rowDiv.appendChild(title);
|
|
361
|
+
rowDiv.appendChild(leader);
|
|
362
|
+
li.appendChild(rowDiv);
|
|
363
|
+
li.appendChild(pageNumber);
|
|
364
|
+
|
|
365
|
+
// Determine nesting level from original TOC
|
|
366
|
+
let level = 0;
|
|
367
|
+
let parent = link.closest('li');
|
|
368
|
+
while (parent) {
|
|
369
|
+
const parentList = parent.closest('ul');
|
|
370
|
+
if (parentList && parentList !== toc) {
|
|
371
|
+
level++;
|
|
372
|
+
parent = parentList.closest('li');
|
|
373
|
+
} else {
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Apply indentation based on level
|
|
379
|
+
if (level > 0) {
|
|
380
|
+
li.style.paddingLeft = (level * 15) + 'px';
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
tocList.appendChild(li);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// Insert the new TOC at the beginning of the document after the title
|
|
387
|
+
const titleWrapper = document.querySelector('.text-center.mb-5.pb-4.border-bottom');
|
|
388
|
+
if (titleWrapper && titleWrapper.nextSibling) {
|
|
389
|
+
document.body.insertBefore(pdfToc, titleWrapper.nextSibling);
|
|
390
|
+
} else {
|
|
391
|
+
document.body.insertBefore(pdfToc, document.body.firstChild);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Force page break before TOC
|
|
395
|
+
pdfToc.style.breakBefore = 'page';
|
|
396
|
+
pdfToc.style.pageBreakBefore = 'always';
|
|
397
|
+
|
|
398
|
+
// Force page break after TOC
|
|
399
|
+
const tocNext = pdfToc.nextElementSibling;
|
|
400
|
+
if (tocNext) {
|
|
401
|
+
tocNext.style.breakBefore = 'page';
|
|
402
|
+
tocNext.style.pageBreakBefore = 'always';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Hide the original TOC
|
|
406
|
+
toc.style.display = 'none';
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
console.log('Generating PDF with proper TOC page numbers...');
|
|
411
|
+
|
|
412
|
+
// First, generate a draft PDF to calculate the page positions of each heading
|
|
413
|
+
const draftPdfBuffer = await page.pdf({
|
|
414
|
+
format: 'A4',
|
|
415
|
+
displayHeaderFooter: true,
|
|
416
|
+
footerTemplate: `
|
|
417
|
+
<div style="width: 100%; text-align: center; font-size: 10pt; margin-top: 10mm;">
|
|
418
|
+
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
|
|
419
|
+
</div>
|
|
420
|
+
`,
|
|
421
|
+
headerTemplate: '<div></div>',
|
|
422
|
+
preferCSSPageSize: true,
|
|
423
|
+
printBackground: true,
|
|
424
|
+
margin: { top: '10mm', bottom: '10mm', left: '10mm', right: '10mm' }
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Now extract the page numbers from the tooltips and update the TOC entries
|
|
428
|
+
await page.evaluate(() => {
|
|
429
|
+
// Find the PDF TOC
|
|
430
|
+
const pdfToc = document.getElementById('pdf-toc');
|
|
431
|
+
if (!pdfToc) return;
|
|
432
|
+
|
|
433
|
+
const tocEntries = pdfToc.querySelectorAll('.toc-page-number');
|
|
434
|
+
const originalToc = document.getElementById('toc');
|
|
435
|
+
|
|
436
|
+
if (originalToc) {
|
|
437
|
+
// Get all links from the original TOC that have tooltip data
|
|
438
|
+
const originalLinks = originalToc.querySelectorAll('a[title], a[data-bs-title]');
|
|
439
|
+
|
|
440
|
+
// Create a mapping from heading IDs to page numbers based on tooltips
|
|
441
|
+
const idToPageMap = {};
|
|
442
|
+
|
|
443
|
+
originalLinks.forEach(link => {
|
|
444
|
+
// Extract the heading ID from href
|
|
445
|
+
const href = link.getAttribute('href');
|
|
446
|
+
if (!href || !href.startsWith('#')) return;
|
|
447
|
+
|
|
448
|
+
const headingId = href.substring(1);
|
|
449
|
+
|
|
450
|
+
// Extract page number from tooltip text (e.g., "Go to page 5")
|
|
451
|
+
const tooltipText = link.getAttribute('title') || link.getAttribute('data-bs-title');
|
|
452
|
+
if (!tooltipText) return;
|
|
453
|
+
|
|
454
|
+
const pageNumberMatch = tooltipText.match(/Go to page (\d+)/i);
|
|
455
|
+
if (pageNumberMatch && pageNumberMatch[1]) {
|
|
456
|
+
const pageNumber = parseInt(pageNumberMatch[1], 10);
|
|
457
|
+
if (!isNaN(pageNumber)) {
|
|
458
|
+
idToPageMap[headingId] = pageNumber;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// Now update the TOC page numbers using the extracted values
|
|
464
|
+
tocEntries.forEach(entry => {
|
|
465
|
+
const targetId = entry.getAttribute('data-for-id');
|
|
466
|
+
if (targetId && idToPageMap[targetId]) {
|
|
467
|
+
entry.textContent = idToPageMap[targetId];
|
|
468
|
+
// Ensure page numbers are clearly visible with proper styling
|
|
469
|
+
entry.style.visibility = 'visible';
|
|
470
|
+
entry.style.opacity = '1';
|
|
471
|
+
entry.style.color = '#000';
|
|
472
|
+
entry.style.background = '#fff';
|
|
473
|
+
entry.style.padding = '0 4px';
|
|
474
|
+
entry.style.fontWeight = 'normal';
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
} else {
|
|
478
|
+
// Fallback to old estimation method if original TOC is not available
|
|
479
|
+
console.log('Original TOC not found, using page number estimation method');
|
|
480
|
+
|
|
481
|
+
// Find all headings with IDs (potential TOC targets)
|
|
482
|
+
const headingsWithIds = Array.from(document.querySelectorAll('h1, h2, h3, h4, h5, h6')).filter(h => h.id);
|
|
483
|
+
|
|
484
|
+
// Use real offsets for more accurate page numbers
|
|
485
|
+
const idToPosition = {};
|
|
486
|
+
|
|
487
|
+
headingsWithIds.forEach(heading => {
|
|
488
|
+
const rect = heading.getBoundingClientRect();
|
|
489
|
+
idToPosition[heading.id] = {
|
|
490
|
+
top: rect.top + window.scrollY,
|
|
491
|
+
id: heading.id
|
|
492
|
+
};
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// Sort by vertical position
|
|
496
|
+
const sortedPositions = Object.values(idToPosition).sort((a, b) => a.top - b.top);
|
|
497
|
+
|
|
498
|
+
// A4 page height (mm to pixels at 96 DPI)
|
|
499
|
+
const pageHeight = 297 * 96 / 25.4;
|
|
500
|
+
const effectivePageHeight = pageHeight - 20; // Account for margins
|
|
501
|
+
|
|
502
|
+
// Start on page 3 (after title and TOC)
|
|
503
|
+
let currentPage = 3;
|
|
504
|
+
let currentOffset = 0;
|
|
505
|
+
|
|
506
|
+
// Calculate page numbers based on relative positions
|
|
507
|
+
sortedPositions.forEach(pos => {
|
|
508
|
+
while (pos.top > currentOffset + effectivePageHeight) {
|
|
509
|
+
currentPage++;
|
|
510
|
+
currentOffset += effectivePageHeight;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
idToPosition[pos.id].page = currentPage;
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// Update TOC entries with calculated page numbers
|
|
517
|
+
tocEntries.forEach(entry => {
|
|
518
|
+
const targetId = entry.getAttribute('data-for-id');
|
|
519
|
+
if (targetId && idToPosition[targetId] && idToPosition[targetId].page) {
|
|
520
|
+
entry.textContent = idToPosition[targetId].page;
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
215
524
|
});
|
|
216
525
|
|
|
217
|
-
//
|
|
526
|
+
// Final PDF generation with correct page numbers
|
|
218
527
|
const pdfBuffer = await page.pdf({
|
|
219
528
|
path: path.resolve(process.cwd(), 'docs/index.pdf'),
|
|
220
529
|
format: 'A4',
|
|
@@ -228,7 +537,7 @@ const pdfLib = require('pdf-lib');
|
|
|
228
537
|
preferCSSPageSize: true,
|
|
229
538
|
printBackground: true,
|
|
230
539
|
quality: 100,
|
|
231
|
-
margin: { top: '10mm', bottom: '10mm', left: '
|
|
540
|
+
margin: { top: '10mm', bottom: '10mm', left: '10mm', right: '10mm' }
|
|
232
541
|
});
|
|
233
542
|
|
|
234
543
|
await browser.close();
|
|
@@ -248,4 +557,4 @@ const pdfLib = require('pdf-lib');
|
|
|
248
557
|
} catch (error) {
|
|
249
558
|
console.error('❌ Error generating PDF:', error);
|
|
250
559
|
}
|
|
251
|
-
})();
|
|
560
|
+
})();
|
|
@@ -47,7 +47,7 @@ module.exports = function (md, templates = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Add the responsive wrapper div before the table
|
|
50
|
-
return '<div class="table-responsive">' + originalTableRender(tokens, idx, options, env, self);
|
|
50
|
+
return '<div class="table-responsive-md">' + originalTableRender(tokens, idx, options, env, self);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
// Override table_close to close the wrapper div
|
|
@@ -256,7 +256,7 @@ module.exports = function (md, templates = {}) {
|
|
|
256
256
|
* @return {String} The rendered HTML output
|
|
257
257
|
*/
|
|
258
258
|
md.renderer.rules.dl_open = function (tokens, idx, options, env, self) {
|
|
259
|
-
const targetHtml = 'terminology-section-start
|
|
259
|
+
const targetHtml = 'terminology-section-start';
|
|
260
260
|
let targetIndex = findTargetIndex(tokens, targetHtml);
|
|
261
261
|
|
|
262
262
|
// Add class to the first <dl> only if it comes after the target HTML
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/* PDF Styling for optimized print layout */
|
|
2
|
-
|
|
3
|
-
/* Target the pdf-document class that's added during PDF generation */
|
|
4
|
-
|
|
5
|
-
/* Reset all margins and paddings */
|
|
6
|
-
.pdf-document * {
|
|
7
|
-
box-sizing: border-box !important;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/* Body and main container styling */
|
|
11
|
-
body.pdf-document {
|
|
12
|
-
max-width: 100% !important;
|
|
13
|
-
width: 100% !important;
|
|
14
|
-
margin: 0 !important;
|
|
15
|
-
padding: 0 !important;
|
|
16
|
-
overflow-x: hidden !important;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/* Extremely aggressive content width adjustment */
|
|
20
|
-
.pdf-document .container,
|
|
21
|
-
.pdf-document main,
|
|
22
|
-
.pdf-document section,
|
|
23
|
-
.pdf-document article,
|
|
24
|
-
.pdf-document .content,
|
|
25
|
-
.pdf-document div[class*="container"],
|
|
26
|
-
.pdf-document div[class*="col-"],
|
|
27
|
-
.pdf-document .row {
|
|
28
|
-
max-width: 95% !important;
|
|
29
|
-
width: 95% !important;
|
|
30
|
-
margin-left: auto !important;
|
|
31
|
-
margin-right: auto !important;
|
|
32
|
-
padding-left: 0 !important;
|
|
33
|
-
padding-right: 0 !important;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/* Override any Bootstrap container constraints */
|
|
37
|
-
.pdf-document .container,
|
|
38
|
-
.pdf-document .container-sm,
|
|
39
|
-
.pdf-document .container-md,
|
|
40
|
-
.pdf-document .container-lg,
|
|
41
|
-
.pdf-document .container-xl {
|
|
42
|
-
max-width: 95% !important;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* Table adjustments */
|
|
46
|
-
.pdf-document table {
|
|
47
|
-
width: 100% !important;
|
|
48
|
-
max-width: 100% !important;
|
|
49
|
-
margin-bottom: 1rem;
|
|
50
|
-
table-layout: fixed !important;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* Header styling */
|
|
54
|
-
.pdf-document .pdf-title {
|
|
55
|
-
font-size: 24pt !important;
|
|
56
|
-
margin-bottom: 0.5rem !important;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* Images in PDF */
|
|
60
|
-
.pdf-document img {
|
|
61
|
-
max-width: 100% !important;
|
|
62
|
-
height: auto !important;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/* Code blocks */
|
|
66
|
-
.pdf-document pre,
|
|
67
|
-
.pdf-document code {
|
|
68
|
-
white-space: pre-wrap !important;
|
|
69
|
-
word-break: break-word !important;
|
|
70
|
-
max-width: 100% !important;
|
|
71
|
-
overflow: visible !important;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* Ensure proper page breaks */
|
|
75
|
-
.pdf-document h1,
|
|
76
|
-
.pdf-document h2,
|
|
77
|
-
.pdf-document h3,
|
|
78
|
-
.pdf-document h4 {
|
|
79
|
-
page-break-after: avoid;
|
|
80
|
-
page-break-inside: avoid;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.pdf-document table,
|
|
84
|
-
.pdf-document figure {
|
|
85
|
-
page-break-inside: avoid;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/* Force any fixed-position elements to static */
|
|
89
|
-
.pdf-document .fixed-top,
|
|
90
|
-
.pdf-document .fixed-bottom,
|
|
91
|
-
.pdf-document .sticky-top,
|
|
92
|
-
.pdf-document .position-fixed,
|
|
93
|
-
.pdf-document .position-sticky {
|
|
94
|
-
position: static !important;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/* Aggressively set all columns to take up more space */
|
|
98
|
-
.pdf-document .col,
|
|
99
|
-
.pdf-document [class*="col-"] {
|
|
100
|
-
flex: 0 0 100% !important;
|
|
101
|
-
max-width: 100% !important;
|
|
102
|
-
padding-left: 0 !important;
|
|
103
|
-
padding-right: 0 !important;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/* ====== DEFINITION LIST STYLING FOR PDF ====== */
|
|
107
|
-
/* Remove background and borders from terms and definitions in PDF */
|
|
108
|
-
.pdf-document dl.terms-and-definitions-list>dt,
|
|
109
|
-
.pdf-document dl.terms-and-definitions-list>dd {
|
|
110
|
-
background-color: transparent !important;
|
|
111
|
-
border: none !important;
|
|
112
|
-
border-radius: 0 !important;
|
|
113
|
-
padding: 0.5rem 0 !important;
|
|
114
|
-
color: #000 !important;
|
|
115
|
-
/* Ensure good page breaks in definition lists */
|
|
116
|
-
page-break-inside: avoid !important;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* Fix spacing between terms */
|
|
120
|
-
.pdf-document dl.terms-and-definitions-list>dt {
|
|
121
|
-
margin-top: 1em !important;
|
|
122
|
-
font-weight: bold !important;
|
|
123
|
-
page-break-after: avoid !important;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/* Hide toggle buttons in PDF output */
|
|
127
|
-
.pdf-document .meta-info-toggle-button {
|
|
128
|
-
display: none !important;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/* Always show meta-info content in PDF */
|
|
132
|
-
.pdf-document dl>dd.meta-info-content-wrapper,
|
|
133
|
-
.pdf-document dl>dd.collapsed.meta-info-content-wrapper {
|
|
134
|
-
display: block !important;
|
|
135
|
-
max-height: none !important;
|
|
136
|
-
height: auto !important;
|
|
137
|
-
overflow: visible !important;
|
|
138
|
-
padding: 0.5rem 0 !important;
|
|
139
|
-
margin: 0 !important;
|
|
140
|
-
line-height: normal !important;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/* Transclusion styling for PDF */
|
|
144
|
-
.pdf-document dt.transcluded-xref-term,
|
|
145
|
-
.pdf-document dd.transcluded-xref-term {
|
|
146
|
-
background: transparent !important;
|
|
147
|
-
background-color: transparent !important;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* Remove any other visual indicators that aren't needed in PDF */
|
|
151
|
-
.pdf-document dl.terms-and-definitions-list>dt::before,
|
|
152
|
-
.pdf-document dl.terms-and-definitions-list>dd::before {
|
|
153
|
-
display: none !important;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/* Ensure all definition content is visible in PDF */
|
|
157
|
-
.pdf-document dl.terms-and-definitions-list dd p {
|
|
158
|
-
padding-left: 0 !important;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/* Improve table display in definitions for PDF */
|
|
162
|
-
.pdf-document dl.terms-and-definitions-list dd table {
|
|
163
|
-
margin: 0.5em 0 !important;
|
|
164
|
-
border-collapse: collapse !important;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
.pdf-document dl.terms-and-definitions-list dd table th,
|
|
168
|
-
.pdf-document dl.terms-and-definitions-list dd table td {
|
|
169
|
-
border: 0.5pt solid #888 !important;
|
|
170
|
-
}
|
|
File without changes
|