pdfkit-markdown
v0.2.0
Published
A markdown renderer for PDFKit using mdast syntax tree.
Downloads
2,582
Readme
PDFKit Markdown Renderer ·
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.