0.2.1 • Published 2 years ago

md-to-pdfmake v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

md-to-pdfmake

Build Status Npm package version

Parser of markdown text to pdfmake object.

Installation


Using npm:

$ npm install md-to-pdfmake

Example:


Mardown Text

Hello World !

**That's a bold text**
**_That's a italic text_**

# That's a big text !

- Item 1
- Item 2

Parsed pdfmake object

[
  { text: 'Hello World' },
  { text: [{ text: "That's a bold text", bold: true }] },
  { text: [{ text: "That's a italic text", italics: true }] },
  { text: "That's a big text" },
  {
    ul: [{ text: 'Item 1' }, { text: 'Item 2' }],
  },
];

API


To parse a markdown string to pdfmake object is simple:

import { toPdfMakeObject } from 'md-to-pdfmake';

const markdownText = '**Hello World**';
const parsedObject = toPdfMakeObject(markdownText);

You can also define the optional style properties provided by pdfmake for each parsed element:

ElementAvailable Properties
pfontSize, lineHeight, characterSpacing, margin
h1,h2,h3,h4,h5,h6fontSize, lineHeight, characterSpacing, margin
lifontSize, lineHeight, characterSpacing, margin
ultype, markerColor
oltype, markerColor, separator, reversed, start

Example using style properties:

import { toPdfMakeObject } from 'md-to-pdfmake';

const markdownText = '# Hello World\n## Welcome'; // h1 and h2
const parsedObject = toPdfMakeObject(markdownText, {
  h1: { fontSize: 20 },
  h2: { fontSize: 18 },
});

Supported elements

  • Paragraph
  • Ordered List
  • Unordered List
  • Headings (h1, h2, h3, h4, h5, h6)
  • Strong
  • Italic
0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago