md-to-pdfmake
v0.3.2
Published
Parser of markdown text to pdfmake object
Downloads
1,702
Readme
md-to-pdfmake
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:
| Element | Available Properties | | --------------------- | ---------------------------------------------- | | a | fontSize, lineHeight, characterSpacing, margin | | p | fontSize, lineHeight, characterSpacing, margin | | h1,h2,h3,h4,h5,h6 | fontSize, lineHeight, characterSpacing, margin | | li | fontSize, lineHeight, characterSpacing, margin | | ul | type, markerColor | | ol | type, 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
- Anchor
- Paragraph
- Ordered List
- Unordered List
- Headings (h1, h2, h3, h4, h5, h6)
- Strong
- Italic