pdfkit-markdown
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

PDFKit Markdown Renderer · npm version

This package provides basic markdown rendering capabilites for PDFKit.

Given a mdast syntax tree as input, content is rendered to a given PDFDocument.

Usage

To render a given markdown string, install:

yarn add pdfkit-markdown unified remark-parse 
import { MarkdownRenderer } from "pdfkit-markdown";
import remarkParse from "remark-parse";
import { unified } from "unified";

...

const tree = unified()
      .use(remarkParse)
      .parse("Markdown **Text**")

new MarkdownRenderer(doc, { /* optional settings */ }).render(tree);

Supported elements

Currently supported elements:

  • Headings
  • Paragraphs and line breaks according to CommonMark specification
  • Bold and italic text
  • List (unordered and ordered)
  • Links
  • Horizontal Rules
  • Code Blocks
  • Inline Code
  • Blockquotes (basic support)

Unsupported elements:

  • Tables
  • Images
  • HTML
  • ...

Configuration

Fonts, sizes, indents etc. are configurable, see documentation on constructor.

Similar packages

https://github.com/maiers/pdfkit-commonmark provides similar functionality, but does not support TypeScript and uses the less maintained CommonMark parser.

Package Sidebar

Install

npm i pdfkit-markdown

Weekly Downloads

1,964

Version

0.2.0

License

MIT

Unpacked Size

22.9 kB

Total Files

6

Last publish

Collaborators

  • fellmann