npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

marked-renderer-pdf

v0.0.5

Published

an extensible PDF-renderer for marked markdown parser

Downloads

6

Readme

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