• Stars
    star
    2,682
  • Rank 17,027 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“„ Markdown to PDF converter

markdown-pdf Build Status Dependency Status Coverage Status

Node module that converts Markdown files to PDFs.

The PDF looks great because it is styled by HTML5 Boilerplate. What? - Yes! Your Markdown is first converted to HTML, then pushed into the HTML5 Boilerplate index.html. Phantomjs renders the page and saves it to a PDF. You can even customise the style of the PDF by passing an optional path to your CSS and you can pre-process your markdown file before it is converted to a PDF by passing in a pre-processing function, for templating.

Install

npm install -g markdown-pdf --ignore-scripts

Note: elevated (sudo) permissions may be needed for npm install -g

Usage

Usage: markdown-pdf [options] <markdown-file-path>

Options:

  -h, --help                             output usage information
  -V, --version                          output the version number
  <markdown-file-path>                   Path of the markdown file to convert
  -c, --cwd [path]                       Current working directory
  -p, --phantom-path [path]              Path to phantom binary
  -h, --runnings-path [path]             Path to runnings (header, footer)
  -s, --css-path [path]                  Path to custom CSS file
  -z, --highlight-css-path [path]        Path to custom highlight-CSS file
  -m, --remarkable-options [json]        Options to pass to Remarkable
  -f, --paper-format [format]            'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'
  -r, --paper-orientation [orientation]  'portrait' or 'landscape'
  -b, --paper-border [measurement]       Supported dimension units are: 'mm', 'cm', 'in', 'px'
  -d, --render-delay [millis]            Delay before rendering the PDF
  -t, --load-timeout [millis]            Timeout before the page is rendered in case `page.onLoadFinished` isn't fired
  -o, --out [path]                       Path of where to save the PDF

markdown-pdf can also be used programmatically:

var markdownpdf = require("markdown-pdf")
  , fs = require("fs")

fs.createReadStream("/path/to/document.md")
  .pipe(markdownpdf())
  .pipe(fs.createWriteStream("/path/to/document.pdf"))

// --- OR ---

markdownpdf().from("/path/to/document.md").to("/path/to/document.pdf", function () {
  console.log("Done")
})

Options

Pass an options object (markdownpdf({/* options */})) to configure the output.

options.cwd

Type: String Default value: process.cwd()

Current working directory.

options.phantomPath

Type: String Default value: Path provided by phantomjs module

Path to the phantomjs binary.

options.cssPath

Type: String Default value: [module path]/markdown-pdf/css/pdf.css

Path to custom CSS file, relative to the current directory.

options.highlightCssPath

Type: String Default value: [module path]/markdown-pdf/css/highlight.css

Path to custom highlight CSS file (for code highlighting with highlight.js), relative to the current directory.

options.paperFormat

Type: String Default value: A4

'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'.

options.paperOrientation

Type: String Default value: portrait

'portrait' or 'landscape'.

options.paperBorder

Type: String Default value: 2cm

Supported dimension units are: 'mm', 'cm', 'in', 'px'

options.runningsPath

Type: String Default value: runnings.js

Path to CommonJS module which sets the page header and footer (see runnings.js).

options.renderDelay

Type: Number Default value: Time until page.onLoadFinished event fired

Delay (in ms) before the PDF is rendered.

options.loadTimeout

Type: Number Default value: 10000

If renderDelay option isn't set, this is the timeout (in ms) before the page is rendered in case the page.onLoadFinished event doesn't fire.

options.preProcessMd

Type: Function Default value: function () { return through() }

A function that returns a through2 stream that transforms the markdown before it is converted to HTML.

options.preProcessHtml

Type: Function Default value: function () { return through() }

A function that returns a through2 stream that transforms the HTML before it is converted to PDF.

options.remarkable

Type: object Default value: { breaks: true }

A config object that is passed to remarkable, the underlying markdown parser.

options.remarkable.preset

Type: String Default value: default

Use remarkable presets as a convenience to quickly enable/disable active syntax rules and options for common use cases.

Supported values are default, commonmark and full

options.remarkable.plugins

Type: Array of remarkable-plugin Functions Default value: []

An array of Remarkable plugin functions, that extend the markdown parser functionality.

options.remarkable.syntax

Type: Array of optional remarkable syntax Stringss Default value: []

An array of optional Remarkable syntax extensions, disabled by default, that extend the markdown parser functionality.

API

from.path(path, opts) / from(path, opts)

Create a readable stream from path and pipe to markdown-pdf. path can be a single path or array of paths.

from.string(string)

Create a readable stream from string and pipe to markdown-pdf. string can be a single string or array of strings.

concat.from.paths(paths, opts)

Create and concatenate readable streams from paths and pipe to markdown-pdf.

concat.from.strings(strings, opts)

Create and concatenate readable streams from strings and pipe to markdown-pdf.

to.path(path, cb) / to(path, cb)

Create a writeable stream to path and pipe output from markdown-pdf to it. path can be a single path, or array of output paths if you specified an array of inputs. The callback function cb will be invoked when data has finished being written.

to.buffer(opts, cb)

Create a concat-stream and pipe output from markdown-pdf to it. The callback function cb will be invoked when the buffer has been created.

to.string(opts, cb)

Create a concat-stream and pipe output from markdown-pdf to it. The callback function cb will be invoked when the string has been created.

More examples

From string to path

var markdownpdf = require("markdown-pdf")

var md = "foo===\n* bar\n* baz\n\nLorem ipsum dolor sit"
  , outputPath = "/path/to/doc.pdf"

markdownpdf().from.string(md).to(outputPath, function () {
  console.log("Created", outputPath)
})

From multiple paths to multiple paths

var markdownpdf = require("markdown-pdf")

var mdDocs = ["home.md", "about.md", "contact.md"]
  , pdfDocs = mdDocs.map(function (d) { return "out/" + d.replace(".md", ".pdf") })

markdownpdf().from(mdDocs).to(pdfDocs, function () {
  pdfDocs.forEach(function (d) { console.log("Created", d) })
})

Concat from multiple paths to single path

var markdownpdf = require("markdown-pdf")

var mdDocs = ["chapter1.md", "chapter2.md", "chapter3.md"]
  , bookPath = "/path/to/book.pdf"

markdownpdf().concat.from(mdDocs).to(bookPath, function () {
  console.log("Created", bookPath)
})

Transform markdown before conversion

var markdownpdf = require("markdown-pdf")
  , split = require("split")
  , through = require("through")
  , duplexer = require("duplexer")

function preProcessMd () {
  // Split the input stream by lines
  var splitter = split()

  // Replace occurences of "foo" with "bar"
  var replacer = through(function (data) {
    this.queue(data.replace(/foo/g, "bar") + "\n")
  })

  splitter.pipe(replacer)
  return duplexer(splitter, replacer)
}

markdownpdf({preProcessMd: preProcessMd})
  .from("/path/to/document.md")
  .to("/path/to/document.pdf", function () { console.log("Done") })

Remarkable options and plugins

Example using remarkable-classy plugin:

var markdownpdf = require("markdown-pdf")

var options = {
    remarkable: {
        html: true,
        breaks: true,
        plugins: [ require('remarkable-classy') ],
		syntax: [ 'footnote', 'sup', 'sub' ]
    }
}

markdownpdf(options)
  .from("/path/to/document.md")
  .to("/path/to/document.pdf", function () { console.log("Done") })

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT Β© Alan Shaw

More Repositories

1

david

πŸ‘“ Node.js module that tells you when your package npm dependencies are out of date.
JavaScript
961
star
2

david-www

πŸ‘“ David helps keep your Node.js project dependencies up to date.
JavaScript
730
star
3

grunt-include-replace

Grunt task to include files and replace variables. Allows for parameterised includes.
JavaScript
200
star
4

ipfs-only-hash

#️⃣ Just enough code to calculate the IPFS hash for some data
JavaScript
119
star
5

grunt-markdown-pdf

Grunt plugin to convert markdown documents to PDF. Thin wrapper around the markdown-pdf module.
JavaScript
76
star
6

embed-video

πŸŽ₯ Get embed HTML code for youtube/vimeo/whatever from URL or ID
JavaScript
68
star
7

it-awesome

πŸ¦„ List of useful modules for working with async iterables
64
star
8

stylist

An adventure workshop to teach CSS
JavaScript
41
star
9

it-pipe

πŸš‡ Utility to "pipe" async iterables together
TypeScript
40
star
10

joi-machine

Generate a Joi schema from some JSON or a JS object
JavaScript
37
star
11

iim

πŸ” IPFS install manager
JavaScript
36
star
12

stripify

Browserify transform that strips console.log lines from your code
JavaScript
35
star
13

leaflet-zoom-min

The leaflet zoom control extended with a button to zoom out to min zoom
JavaScript
32
star
14

meteor-browpie

Live updated pie charts of browser usage share
JavaScript
28
star
15

upmon

Super simple service health monitoring.
JavaScript
26
star
16

meteor-foam

A mass of bubbles of photos in a matrix of liquid internet, especially an accumulation of fine, frothy bubbles formed in or on the surface of a liquid, as from agitation or fermentation or Meteor and d3.
JavaScript
25
star
17

it-to-stream

🚰 Convert streaming iterables to Node.js streams
JavaScript
21
star
18

libp2p-dht-scrape-aas

🧹 A libp2p DHT scraper as a service allowing anyone to collect, consume and use to generate useful reports & visualisations.
Go
21
star
19

ipfs-browser-sandbox

πŸͺ An EXPERIMENTAL p2p browser built on IPFS
JavaScript
21
star
20

meteor-blackboard

JavaScript
20
star
21

pagination-freemarker-macros

I couldn’t find a good set of macros to help navigate through paginated data so I wrote my own.
FreeMarker
15
star
22

it-pushable

Pushable iterable
TypeScript
13
star
23

go-carbites

πŸš— πŸš™ πŸš• Chunking for CAR files. Split a single CAR into multiple CARs.
Go
13
star
24

br-chrome-tabs

Browserify compatible HTML/CSS and JS chrome tabs implementation
CSS
12
star
25

abortable-iterator

Make any iterator or iterable abortable via an AbortSignal
TypeScript
11
star
26

nodeunit-lcov-coveralls-example

An example of how the nodeunit lcov reporter can be used to send coverage data to coveralls
JavaScript
11
star
27

meteor-spotify

Meteor Spotify DJ
JavaScript
10
star
28

chatterbox-webext

🧭 A p2p messaging application built on IPFS and libp2p
JavaScript
9
star
29

pull-stream-to-async-iterator

Convert a pull stream to an async iterator
JavaScript
9
star
30

upmon-tray

The upmon tray application.
JavaScript
8
star
31

async-iterator-to-pull-stream

Convert a (async) iterator to a pull stream
JavaScript
7
star
32

md-tokenizer

Streaming markdown tokenizer
JavaScript
7
star
33

ipfs-ds-postgres

🐘 PostgreSQL datastore for IPFS
Go
7
star
34

stream-to-it

🚰 Convert Node.js streams to streaming iterables
JavaScript
7
star
35

php-http-digest-auth

I could only find one other PHP based HTTP digest auth example on the internet…and it looked as though it might not even work. I wrote an abstract class as a base that allows you to easily build your own implementation.
PHP
7
star
36

tessel-caas

Tessel camera as a service is a couple of scripts that expose a feed to the Tessel camera module over a dnode connection.
JavaScript
7
star
37

carstream

πŸš—πŸ’¦ Web stream CAR reader and writer.
JavaScript
6
star
38

js-libp2p-quic

QUIC transport for libp2p
JavaScript
6
star
39

w3name

Simple mutability for Web3.Storage.
JavaScript
6
star
40

meteor-asciify

An IM client written in Meteor (http://www.meteor.com/) and using asciify (https://npmjs.org/package/asciify)
JavaScript
6
star
41

tut-flow-control

Live coding session designed to show the fundamentals of async in node/javascript.
JavaScript
5
star
42

js-lotus-client-examples

Examples for using the Lotus RPC API with `js-lotus-client`.
TypeScript
5
star
43

encodeuricomponent-tag

Template literal tag for encoding URI component values
JavaScript
5
star
44

cf-workers-idbkv

IndexedDB (IDB) backed Cloudflare workers KV store for testing.
TypeScript
5
star
45

cf-workers-kv

Cloudflare workers KV with customizable backing store for testing.
TypeScript
5
star
46

iterable-ndjson

πŸ€Ήβ€β™€οΈ ndjson as async iterator
JavaScript
5
star
47

js-ipfs-preload-tester

Sanity check a preload server is working as expected.
JavaScript
5
star
48

paramap-it

βˆ₯ Parallel mapping for async iterators
JavaScript
5
star
49

ohmigrate

Minimal framework for migrating databases or whatever from one version to the next
JavaScript
4
star
50

hoodie-plugin-reactive

Simple reactive mustache based templating for hoodie using ractive.js
JavaScript
4
star
51

babel-plugin-import-rename

Rename import sources
JavaScript
4
star
52

funify

Browserify transform that turns funjs into js
JavaScript
4
star
53

uploadcare-cdn

Perform image transformations on uploadcare URLs https://uploadcare.com/documentation/cdn/
JavaScript
4
star
54

cardex

☝️ Indexes for CARs
JavaScript
4
star
55

JavaScript-Image-Optimiser

JSIO is a tiny library that allows you to make fewer requests to your server by packaging all your site image data in a JavaScript file in data uri format.
JavaScript
4
star
56

springx-freemarker-macros

Extensions to the default spring macros (spring.ftl) and other useful utilities.
4
star
57

chatterbox-relay

🎾 A Chatterbox pubsub relay server
JavaScript
4
star
58

jacksonscript

What if there was a super simple language for beginners without all the WTF of JavaScript?
3
star
59

cljs-compiler

Clojurescript compiler
JavaScript
3
star
60

chatterbox-core

πŸ“¬ The core API for Chatterbox, a messaging application built on IPFS and libp2p
TypeScript
3
star
61

node-crazyflie-keyboard

The canonical control the quad copter with a keyboard example
JavaScript
3
star
62

swapify

Swap out your requires!
JavaScript
3
star
63

pdiddy-client

p2p ddp client
JavaScript
3
star
64

joi-shortid

Joi validation for shortid
JavaScript
3
star
65

p-fifo

🚦 Promised First-In-First-Out buffer. Await on push to be told when a value is consumed and await on shift for a value to consume when the buffer is empty.
JavaScript
3
star
66

xgettext-regex

Minimum viable xgettext .pot file generator. Uses a configurable regex to get translation keys.
JavaScript
3
star
67

querystring-stable-stringify

Deterministic querystring.stringify().
JavaScript
3
star
68

gamut

Range generator
JavaScript
2
star
69

london-districts

A list of London districts from wikipedia
JavaScript
2
star
70

it-block

Transform input into equally-sized blocks of output using async iterators
TypeScript
2
star
71

md-parser

Streaming markdown parser
JavaScript
2
star
72

emitterator

Async iterator to event emitter
JavaScript
2
star
73

express-single-session

Express middleware that enforces a single session per user
JavaScript
2
star
74

get-iterator

Get the default iterator or async iterator for an Iterable.
TypeScript
2
star
75

meteor-react-redux-base

Scaffolding for Meteor + React + Redux
JavaScript
2
star
76

recoverable-iterator

If an iterator errors, restart and continue.
JavaScript
2
star
77

david-status-api

Aggregation of project and info APIs.
JavaScript
2
star
78

it-reader

πŸ“– Read an exact number of bytes from a binary (async) iterable
TypeScript
2
star
79

distribase

IPFS backed LevelDOWN compatible store for use with LevelUP
JavaScript
2
star
80

david-www-infrastructure

Ansible scripts for deploying the david-dm.org website
2
star
81

tut-middleware

JavaScript
2
star
82

ipfs-hookds

πŸ΄β€β˜ οΈA wrapper for an IPFS datastore that adds optional before and after hooks to it's methods.
Go
2
star
83

meat-fighter-2-turbo

An experiment with meteor and websockets.
JavaScript
2
star
84

gruntend

Boilerplate for frontend development using HTML5 Boilerplate, mobile first styles, CoffeeScript and LESS
CSS
2
star
85

nodeit

NodeJS text editor
JavaScript
2
star
86

hoodie-plugin-tweets

Exposes a public database of filtered tweets.
JavaScript
2
star
87

splate

The simplest possible JavaScript templating engine that could work
JavaScript
2
star
88

meteor-movements

Animated ship movements on a leaflet map updated as they happen
JavaScript
2
star
89

genplate

Streaming templates where template data is retrieved asynchronously using generators
JavaScript
2
star
90

swingometeor

JavaScript
2
star
91

ipld-formats

πŸ—„ Tool to create a directory with all the configured IPLD format modules and all their versions for adding to IPFS
JavaScript
2
star
92

js-libp2p-webext-mdns

libp2p MDNS discovery for web extensions
JavaScript
2
star
93

programming-in-go-exercises

Exercise answers from "An Introduction to Programming in Go" http://www.golang-book.com/
Go
2
star
94

multiwriter

πŸ€Έβ€β™€οΈ A writer that writes to multiple other writers and the writers can be added and removed dynamically.
Go
2
star
95

stream-from-to

Utility for piping to/from a stream from a variety of sources to a variety of destinations
JavaScript
2
star
96

miniswap

Miniature Bitswap implementation, remote read only.
JavaScript
2
star
97

drand-relay-w3s

A drand relay that publishes randomness to IPFS, Filecoin and maintains an IPNS record pointing at the latest value.
JavaScript
2
star
98

hoodie-plugin-memory-store

Stores stuff in memory, optionally syncs to the passed remote store.
JavaScript
2
star
99

cosnole

Typo in console?
JavaScript
2
star
100

meteor-shiny

Presentation showing off some demos created with Meteor
JavaScript
2
star