开源软件名称(OpenSource Name):alanshaw/markdown-pdf开源软件地址(OpenSource Url):https://github.com/alanshaw/markdown-pdf开源编程语言(OpenSource Language):JavaScript 58.6%开源软件介绍(OpenSource Introduction):markdown-pdfNode 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 Installnpm install -g markdown-pdf --ignore-scripts Note: elevated (sudo) permissions may be needed for Usage
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")
}) OptionsPass an options object ( options.cwdType: Current working directory. options.phantomPathType: Path to the phantomjs binary. options.cssPathType: Path to custom CSS file, relative to the current directory. options.highlightCssPathType: Path to custom highlight CSS file (for code highlighting with highlight.js), relative to the current directory. options.paperFormatType: 'A3', 'A4', 'A5', 'Legal', 'Letter' or 'Tabloid'. options.paperOrientationType: 'portrait' or 'landscape'. options.paperBorderType: Supported dimension units are: 'mm', 'cm', 'in', 'px' options.runningsPathType: Path to CommonJS module which sets the page header and footer (see runnings.js). options.renderDelayType: Delay (in ms) before the PDF is rendered. options.loadTimeoutType: If options.preProcessMdType: A function that returns a through2 stream that transforms the markdown before it is converted to HTML. options.preProcessHtmlType: A function that returns a through2 stream that transforms the HTML before it is converted to PDF. options.remarkableType: A config object that is passed to remarkable, the underlying markdown parser. options.remarkable.presetType: Use remarkable presets as a convenience to quickly enable/disable active syntax rules and options for common use cases. Supported values are options.remarkable.pluginsType: An array of Remarkable plugin functions, that extend the markdown parser functionality. options.remarkable.syntaxType: An array of optional Remarkable syntax extensions, disabled by default, that extend the markdown parser functionality. APIfrom.path(path, opts) / from(path, opts)Create a readable stream from from.string(string)Create a readable stream from concat.from.paths(paths, opts)Create and concatenate readable streams from concat.from.strings(strings, opts)Create and concatenate readable streams from to.path(path, cb) / to(path, cb)Create a writeable stream to to.buffer(opts, cb)Create a concat-stream and pipe output from markdown-pdf to it. The callback function to.string(opts, cb)Create a concat-stream and pipe output from markdown-pdf to it. The callback function More examplesFrom string to pathvar 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 pathsvar 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 pathvar 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 conversionvar 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 pluginsExample 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") }) ContributeFeel free to dive in! Open an issue or submit PRs. LicenseMIT © Alan Shaw |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论