0.1.1 • Published 1 year ago

pdfkit-markdown v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

0.1.1

1 year ago

0.1.0

1 year ago