New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

marked-renderer-pdf

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marked-renderer-pdf

an extensible PDF-renderer for marked markdown parser

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
2
Created
Source

marked-renderer-pdf

Converts Markdown to PDF.

This package contains a custom renderer for marked generating AST of parsed markdown document. This AST is then used to generate PDF documents with pdfjs.

This converter does not converting markdown to HTML, first, to be converted to PDF using some headless browser afterwards. The conversion works offline. Due to either involved dependency working in a client's browser this tool might completely work in a client's browser, too, if this project's code is prepared for running in browser (basically requiring transpiling and some packaging).

Installation

npm i -P marked-renderer-pdf

Usage

const File = require( "fs" );
const Converter = require( "marked-renderer-pdf" );

const md = `
This is _some_ **simple _test_** text.

* Here is an outer list
* which is unordered  
  and has line breaks and
  1. might contain a subordinated list
  2. which should be
  3. properly rendered even _though **containing ~extra~**_ **styled ~text~**
     * and support line  
       breaks as well
  4. and has to deal with continuation in
* superordinated lists  
  with more items.

## List of Employees

| first name | last name |
| --- | --- |
| John | Doe |
| Jane | Foo Bar |
`;


Converter.convertString( md, {
	smartyPants: true,
} )
	.then( doc => {
		doc.pipe( File.createWriteStream( "test.pdf" ) );

		return doc.end();
	} )
	.catch( error => console.error( error ) ); // eslint-disable-line no-console

Features

This library relies on markdown flavours supported by marked and PDF rendering capabilities supported by pdfjs. It supports themes implemented in code, thus enabling derived themes to implement a company's corporate design or similar.

Browser Support

This converter works in browser without any server-side backend involved.

You may use a published archive or build one yourself. In either case you might use the converter in an HTML document like this:

<a id="some-link"></a>
<script type="text/javascript" src="path/to/markdown-to-pdf/converter.min.js"></script>
<script type="text/javascript">
MarkdownToPdf
	.convertString( "some **structured _text_** using markdown syntax" )
	.then( function( pdf ) { 
		const link = document.getElementById( "some-link" );

		link.href = URL.createObjectURL( new Blob( [pdf], {
			type: "application/pdf",
		} ) );
	} );
</script>

Build It Yourself

Checking out the project from git is required to access the script building version for browser yourself.

Open CLI in folder of your working copy of project and run:

npm run build-browser

This script is creating a folder /dist containing an HTML document providing sandbox for testing conversion live in browser. In addition there is a file main.js which is equal to the file converter.min.js in a deployed version.

License

MIT

Keywords

markdown

FAQs

Package last updated on 22 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts