@speajus/markdown-to-pdf 1.0.9 → 1.0.10
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/README.md +3 -1
- package/README.pdf +0 -0
- package/dist/renderer.js +13 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Basic-Markdown-To-PDF
|
|
2
2
|
|
|
3
|
-
A lightweight TypeScript library that converts Markdown files into styled PDF documents. Built on [marked](https://github.com/markedjs/marked) for parsing and [PDFKit](https://pdfkit.org/) for PDF generation. [README.pdf](./README.pdf)
|
|
3
|
+
A lightweight TypeScript library that converts Markdown files into styled PDF documents. Built on [marked](https://github.com/markedjs/marked) for parsing and [PDFKit](https://pdfkit.org/) for PDF generation. [README.pdf](./README.pdf) | [Live Demo](https://speajus.github.io/markdown-to-pdf/)
|
|
4
|
+
|
|
5
|
+
[](https://speajus.github.io/markdown-to-pdf/)
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
package/README.pdf
CHANGED
|
Binary file
|
package/dist/renderer.js
CHANGED
|
@@ -361,6 +361,11 @@ async function renderMarkdownToPdf(markdown, options) {
|
|
|
361
361
|
resetBodyFont();
|
|
362
362
|
}
|
|
363
363
|
function renderLink(tok, continued) {
|
|
364
|
+
// If the link wraps an image, render a clickable image instead of text
|
|
365
|
+
const imgChild = tok.tokens?.find((t) => t.type === 'image');
|
|
366
|
+
if (imgChild) {
|
|
367
|
+
return renderImage(imgChild, tok.href);
|
|
368
|
+
}
|
|
364
369
|
if (headingCtx) {
|
|
365
370
|
doc.font(headingCtx.font).fontSize(headingCtx.fontSize).fillColor(theme.linkColor);
|
|
366
371
|
}
|
|
@@ -403,7 +408,7 @@ async function renderMarkdownToPdf(markdown, options) {
|
|
|
403
408
|
break;
|
|
404
409
|
}
|
|
405
410
|
case 'link': {
|
|
406
|
-
renderLink(tok, cont);
|
|
411
|
+
await renderLink(tok, cont);
|
|
407
412
|
break;
|
|
408
413
|
}
|
|
409
414
|
case 'image': {
|
|
@@ -435,7 +440,7 @@ async function renderMarkdownToPdf(markdown, options) {
|
|
|
435
440
|
}
|
|
436
441
|
}
|
|
437
442
|
}
|
|
438
|
-
async function renderImage(tok) {
|
|
443
|
+
async function renderImage(tok, linkUrl) {
|
|
439
444
|
try {
|
|
440
445
|
// Use the pluggable image renderer
|
|
441
446
|
const imgBuffer = await imageRenderer(tok.href);
|
|
@@ -452,7 +457,13 @@ async function renderMarkdownToPdf(markdown, options) {
|
|
|
452
457
|
displayWidth = img.width * (displayHeight / img.height);
|
|
453
458
|
}
|
|
454
459
|
ensureSpace(displayHeight + 10);
|
|
460
|
+
const imgX = doc.x;
|
|
461
|
+
const imgY = doc.y;
|
|
455
462
|
doc.image(imgBuffer, { width: displayWidth, height: displayHeight });
|
|
463
|
+
// If the image is wrapped in a link, overlay a clickable annotation
|
|
464
|
+
if (linkUrl) {
|
|
465
|
+
doc.link(imgX, imgY, displayWidth, displayHeight, linkUrl);
|
|
466
|
+
}
|
|
456
467
|
doc.moveDown(0.5);
|
|
457
468
|
}
|
|
458
469
|
catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speajus/markdown-to-pdf",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A new project created with Intent by Augment.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
32
|
"build": "tsc && mkdir -p dist/fonts && cp src/fonts/* dist/fonts/",
|