@speajus/markdown-to-pdf 1.0.9 → 1.0.11

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 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
+ [![Live Demo](./docs/image.png)](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 {
@@ -578,6 +589,17 @@ async function renderMarkdownToPdf(markdown, options) {
578
589
  renderTextWithEmoji(t.text);
579
590
  }
580
591
  headingCtx = null;
592
+ // Draw an underline beneath h1 and h2
593
+ if (t.depth <= 2) {
594
+ const lineY = doc.y + 2;
595
+ doc.save();
596
+ doc.strokeColor(theme.horizontalRuleColor).lineWidth(t.depth === 1 ? 1.5 : 1)
597
+ .moveTo(margins.left, lineY)
598
+ .lineTo(margins.left + contentWidth, lineY)
599
+ .stroke();
600
+ doc.restore();
601
+ doc.y = lineY + 2;
602
+ }
581
603
  doc.moveDown(spaceBelow / doc.currentLineHeight());
582
604
  resetBodyFont();
583
605
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speajus/markdown-to-pdf",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
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/",