markdown-pdf
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -6,3 +6,3 @@ var system = require("system") | ||
// Read in arguments | ||
var args = ["in", "out", "runningsPath", "cssPath", "highlightCssPath", "paperFormat", "paperOrientation", "paperBorder", "renderDelay", "jsonPath"].reduce(function (args, name, i) { | ||
var args = ["in", "out", "cwd", "runningsPath", "cssPath", "highlightCssPath", "paperFormat", "paperOrientation", "paperBorder", "renderDelay", "jsonPath"].reduce(function (args, name, i) { | ||
args[name] = system.args[i + 1] | ||
@@ -12,55 +12,34 @@ return args | ||
page.open(page.libraryPath + "/../html5bp/index.html", function (status) { | ||
if (status == "fail") { | ||
page.close() | ||
phantom.exit(1) | ||
return | ||
} | ||
// Add custom CSS to the page | ||
page.evaluate(function(cssPaths) { | ||
var head = document.querySelector("head") | ||
cssPaths.forEach(function(cssPath) { | ||
var css = document.createElement("link") | ||
css.rel = "stylesheet" | ||
css.href = cssPath | ||
head.appendChild(css) | ||
var html5bpPath = page.libraryPath + "/../html5bp" | ||
}); | ||
}, [args.cssPath, args.highlightCssPath]) | ||
// Add the HTML to the page | ||
page.evaluate(function(html) { | ||
var body = document.querySelector("body") | ||
var html = fs.read(html5bpPath + "/index.html") | ||
.replace(/\{\{baseUrl\}\}/g, "file://" + html5bpPath) | ||
.replace("{{content}}", fs.read(args.in)) | ||
// Remove the paragraph HTML5 boilerplate adds | ||
body.removeChild(document.querySelector("p")) | ||
var container = document.createElement("div") | ||
container.innerHTML = html | ||
body.appendChild(container) | ||
}, fs.read(args.in)) | ||
// Set the PDF paper size | ||
page.paperSize = paperSize(args.runningsPath, {format: args.paperFormat, orientation: args.paperOrientation, border: args.paperBorder}) | ||
page.setContent(html, "file://" + args.cwd + "/markdown-pdf.html") | ||
// Render the page | ||
setTimeout(function () { | ||
page.render(args.out) | ||
page.close() | ||
phantom.exit(0) | ||
}, parseInt(args.renderDelay, 10)) | ||
}) | ||
// Add custom CSS to the page | ||
page.evaluate(function (cssPaths) { | ||
var head = document.querySelector("head") | ||
function paperSize(runningsPath, obj) { | ||
cssPaths.forEach(function (cssPath) { | ||
var css = document.createElement("link") | ||
css.rel = "stylesheet" | ||
css.href = cssPath | ||
head.appendChild(css) | ||
}) | ||
}, [args.cssPath, args.highlightCssPath]) | ||
// Set the PDF paper size | ||
page.paperSize = paperSize(args.runningsPath, {format: args.paperFormat, orientation: args.paperOrientation, border: args.paperBorder}) | ||
// Render the page | ||
setTimeout(function () { | ||
page.render(args.out) | ||
page.close() | ||
phantom.exit(0) | ||
}, parseInt(args.renderDelay, 10)) | ||
function paperSize (runningsPath, obj) { | ||
var runnings = require(runningsPath) | ||
@@ -67,0 +46,0 @@ |
var fs = require("fs") | ||
, path = require("path") | ||
, through = require("through") | ||
, through = require("through2") | ||
, extend = require("extend") | ||
@@ -16,19 +16,7 @@ , marked = require("marked") | ||
opts = opts || {} | ||
opts.cwd = opts.cwd ? path.resolve(opts.cwd) : process.cwd() | ||
opts.phantomPath = opts.phantomPath || require("phantomjs").path | ||
opts.runningsPath = path.resolve(__dirname + "/..", opts.runningsPath || '') || __dirname + "/runnings.js" | ||
opts.cssPath = opts.cssPath || __dirname + "/../pdf.css" | ||
var relativeCssPath = path.resolve(process.cwd(), opts.cssPath) | ||
if (fs.existsSync(relativeCssPath)) { | ||
opts.cssPath = relativeCssPath | ||
} | ||
opts.highlightCssPath = opts.highlightCssPath || __dirname + "/../highlight.css" | ||
var relativeHighlightCssPath = path.resolve(process.cwd(), opts.highlightCssPath) | ||
if (fs.existsSync(relativeHighlightCssPath)) { | ||
opts.highlightCssPath = relativeHighlightCssPath | ||
} | ||
opts.runningsPath = opts.runningsPath ? path.resolve(opts.runningsPath) : path.join(__dirname, "runnings.js") | ||
opts.cssPath = opts.cssPath ? path.resolve(opts.cssPath) : path.join(__dirname, "..", "pdf.css") | ||
opts.highlightCssPath = opts.highlightCssPath ? path.resolve(opts.highlightCssPath) : path.join(__dirname, "..", "highlight.css") | ||
opts.paperFormat = opts.paperFormat || "A4" | ||
@@ -45,6 +33,7 @@ opts.paperOrientation = opts.paperOrientation || "portrait" | ||
var mdToHtml = through( | ||
function write (data) { | ||
function transform (data, enc, cb) { | ||
md += data | ||
cb() | ||
}, | ||
function end () { | ||
function flush (cb) { | ||
var self = this | ||
@@ -62,4 +51,5 @@ | ||
marked(md, markedOptions, function (er, html) { | ||
self.queue(html) | ||
self.queue(null) | ||
self.push(html) | ||
self.push(null) | ||
cb() | ||
}) | ||
@@ -93,2 +83,3 @@ } | ||
, tmpPdfPath | ||
, opts.cwd | ||
, opts.runningsPath | ||
@@ -95,0 +86,0 @@ , opts.cssPath |
{ | ||
"name": "markdown-pdf", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Markdown to PDF converter", | ||
"main": "index.js", | ||
"main": "lib/markdown-pdf.js", | ||
"scripts": { | ||
"test": "mocha", | ||
"coveralls": "jscoverage lib && MARKDOWNPDF_COV=1 mocha -R mocha-lcov-reporter | coveralls", | ||
"coverage": "MARKDOWNPDF_COV=1 mocha -R html-cov > coverage.html" | ||
"test": "istanbul cover node_modules/.bin/tape test/*.js", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls" | ||
}, | ||
@@ -30,18 +29,17 @@ "repository": { | ||
"dependencies": { | ||
"marked": "^0.3.2", | ||
"phantomjs": "^1.9.11", | ||
"tmp": "^0.0.18", | ||
"commander": "^2.2.0", | ||
"through": "^2.3.4", | ||
"duplexer": "^0.1.1", | ||
"extend": "^2.0.0", | ||
"duplexer": "^0.1.1", | ||
"marked": "^0.3.2", | ||
"phantomjs": "^1.9.13", | ||
"pygmentize-bundled": "^2.2.0", | ||
"stream-from-to": "^1.4.0", | ||
"pygmentize-bundled": "^2.2.0" | ||
"through2": "^0.6.3", | ||
"tmp": "0.0.24" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.0.1", | ||
"mocha-lcov-reporter": "^0.0.1", | ||
"coveralls": "^2.10.0", | ||
"jscoverage": "^0.5.3", | ||
"pdf-text": "^0.4.0" | ||
"istanbul": "^0.3.5", | ||
"pdf-text": "^0.4.0", | ||
"tape": "^3.0.3" | ||
}, | ||
@@ -48,0 +46,0 @@ "engines": { |
@@ -1,2 +0,2 @@ | ||
markdown-pdf [](https://travis-ci.org/alanshaw/markdown-pdf) [](https://david-dm.org/alanshaw/markdown-pdf) [](https://coveralls.io/r/alanshaw/markdown-pdf?branch=master) | ||
markdown-pdf [](https://travis-ci.org/alanshaw/markdown-pdf) [](https://david-dm.org/alanshaw/markdown-pdf) [](https://coveralls.io/r/alanshaw/markdown-pdf?branch=master) | ||
=== | ||
@@ -87,3 +87,3 @@ | ||
A function that returns a [through stream](https://npmjs.org/package/through) that transforms the markdown before it is converted to HTML. | ||
A function that returns a [through2 stream](https://npmjs.org/package/through2) that transforms the markdown before it is converted to HTML. | ||
@@ -94,3 +94,3 @@ #### options.preProcessHtml | ||
A function that returns a [through stream](https://npmjs.org/package/through) that transforms the HTML before it is converted to PDF. | ||
A function that returns a [through2 stream](https://npmjs.org/package/through2) that transforms the HTML before it is converted to PDF. | ||
@@ -97,0 +97,0 @@ API |
@@ -1,6 +0,6 @@ | ||
var markdownpdf = require("../") | ||
, assert = require("assert") | ||
, fs = require("fs") | ||
var fs = require("fs") | ||
, test = require("tape") | ||
, markdownpdf = require("../") | ||
, tmp = require("tmp") | ||
, through = require("through") | ||
, through = require("through2") | ||
, pdfText = require("pdf-text") | ||
@@ -10,49 +10,46 @@ | ||
describe("markdownpdf", function() { | ||
test("generate a nonempty PDF from ipsum.md", function (t) { | ||
t.plan(4) | ||
it("should generate a nonempty PDF from ipsum.md", function (done) { | ||
this.timeout(5000) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
t.ifError(er) | ||
fs.close(tmpPdfFd) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
assert.ifError(er) | ||
fs.close(tmpPdfFd) | ||
markdownpdf().from(__dirname + "/fixtures/ipsum.md").to(tmpPdfPath, function (er) { | ||
t.ifError(er) | ||
markdownpdf().from(__dirname + "/fixtures/ipsum.md").to(tmpPdfPath, function (er) { | ||
assert.ifError(er) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
assert.ifError(er) | ||
// Test not empty | ||
assert.ok(data.length > 0) | ||
done() | ||
}) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
t.ifError(er) | ||
// Test not empty | ||
t.ok(data.length > 0) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("should have a header and footer", function (done) { | ||
this.timeout(5000) | ||
test("output should have a header and footer", function (t) { | ||
t.plan(7) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
assert.ifError(er) | ||
fs.close(tmpPdfFd) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
t.ifError(er) | ||
fs.close(tmpPdfFd) | ||
markdownpdf({runningsPath: __dirname+'/fixtures/runnings.js'}).from(__dirname + "/fixtures/ipsum.md").to(tmpPdfPath, function (er) { | ||
assert.ifError(er) | ||
markdownpdf({runningsPath: __dirname+'/fixtures/runnings.js'}).from(__dirname + "/fixtures/ipsum.md").to(tmpPdfPath, function (er) { | ||
t.ifError(er) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
assert.ifError(er) | ||
// Test not empty | ||
assert.ok(data.length > 0) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
t.ifError(er) | ||
// Test not empty | ||
t.ok(data.length > 0) | ||
// Header and footer included? | ||
pdfText(tmpPdfPath, function (er, chunks) { | ||
assert.ifError(er) | ||
// Header and footer included? | ||
pdfText(tmpPdfPath, function (er, chunks) { | ||
t.ifError(er) | ||
assert.ok(/Some\s?Header/.test(chunks.join(''))) | ||
assert.ok(/Some\s?Footer/.test(chunks.join(''))) | ||
done() | ||
}) | ||
t.ok(/Some\s?Header/.test(chunks.join(''))) | ||
t.ok(/Some\s?Footer/.test(chunks.join(''))) | ||
t.end() | ||
}) | ||
@@ -62,94 +59,93 @@ }) | ||
}) | ||
}) | ||
it("should call preProcessMd hook", function (done) { | ||
this.timeout(5000) | ||
test("should call preProcessMd hook", function (t) { | ||
t.plan(3) | ||
var writeCount = 0 | ||
, preProcessMd = function () { return through(function (data) { writeCount++; this.queue(data) }) } | ||
var writeCount = 0 | ||
, preProcessMd = function () { return through(function (data, enc, cb) { writeCount++; this.push(data); cb() }) } | ||
markdownpdf({preProcessMd: preProcessMd}).from(__dirname + "/fixtures/ipsum.md").to.string(function (er, pdfStr) { | ||
assert.ifError(er) | ||
markdownpdf({preProcessMd: preProcessMd}).from(__dirname + "/fixtures/ipsum.md").to.string(function (er, pdfStr) { | ||
t.ifError(er) | ||
// Test not empty | ||
assert.ok(pdfStr.length > 0) | ||
assert(writeCount > 0, "Write count expected to be > 0") | ||
done() | ||
}) | ||
// Test not empty | ||
t.ok(pdfStr.length > 0) | ||
t.ok(writeCount > 0, "Write count expected to be > 0") | ||
t.end() | ||
}) | ||
}) | ||
it("should call preProcessHtml hook", function (done) { | ||
this.timeout(5000) | ||
test("should call preProcessHtml hook", function (t) { | ||
t.plan(3) | ||
var writeCount = 0 | ||
, preProcessHtml = function () { return through(function (data) { writeCount++; this.queue(data) }) } | ||
var writeCount = 0 | ||
, preProcessHtml = function () { return through(function (data, enc, cb) { writeCount++; this.push(data); cb() }) } | ||
markdownpdf({preProcessHtml: preProcessHtml}).from(__dirname + "/fixtures/ipsum.md").to.string(function (er, pdfStr) { | ||
assert.ifError(er) | ||
markdownpdf({preProcessHtml: preProcessHtml}).from(__dirname + "/fixtures/ipsum.md").to.string(function (er, pdfStr) { | ||
t.ifError(er) | ||
// Test not empty | ||
assert.ok(pdfStr.length > 0) | ||
assert(writeCount > 0, "Write count expected to be > 0") | ||
done() | ||
}) | ||
// Test not empty | ||
t.ok(pdfStr.length > 0) | ||
t.ok(writeCount > 0, "Write count expected to be > 0") | ||
t.end() | ||
}) | ||
}) | ||
it("should concatenate source files", function (done) { | ||
this.timeout(5000) | ||
test("should concatenate source files", function (t) { | ||
t.plan(4) | ||
var files = [ | ||
__dirname + "/fixtures/first.md" | ||
, __dirname + "/fixtures/second.md" | ||
] | ||
var files = [ | ||
__dirname + "/fixtures/first.md" | ||
, __dirname + "/fixtures/second.md" | ||
] | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
assert.ifError(er) | ||
fs.close(tmpPdfFd) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath, tmpPdfFd) { | ||
t.ifError(er) | ||
fs.close(tmpPdfFd) | ||
markdownpdf().concat.from(files).to(tmpPdfPath, function (er) { | ||
assert.ifError(er) | ||
markdownpdf().concat.from(files).to(tmpPdfPath, function (er) { | ||
t.ifError(er) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
assert.ifError(er) | ||
// Test not empty | ||
assert.ok(data.length > 0) | ||
done() | ||
}) | ||
// Read the file | ||
fs.readFile(tmpPdfPath, {encoding: "utf8"}, function (er, data) { | ||
t.ifError(er) | ||
// Test not empty | ||
t.ok(data.length > 0) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("should write to multiple paths when converting multiple files", function (done) { | ||
this.timeout(5000) | ||
test("should write to multiple paths when converting multiple files", function (t) { | ||
t.plan(6) | ||
var files = [ | ||
__dirname + "/fixtures/first.md" | ||
, __dirname + "/fixtures/second.md" | ||
] | ||
var files = [ | ||
__dirname + "/fixtures/first.md" | ||
, __dirname + "/fixtures/second.md" | ||
] | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath0, tmpPdfFd0) { | ||
assert.ifError(er) | ||
fs.close(tmpPdfFd0) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath0, tmpPdfFd0) { | ||
t.ifError(er) | ||
fs.close(tmpPdfFd0) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath1, tmpPdfFd1) { | ||
assert.ifError(er) | ||
fs.close(tmpPdfFd1) | ||
tmp.file({postfix: ".pdf"}, function (er, tmpPdfPath1, tmpPdfFd1) { | ||
t.ifError(er) | ||
fs.close(tmpPdfFd1) | ||
markdownpdf().from.paths(files).to.paths([tmpPdfPath0, tmpPdfPath1], function (er) { | ||
assert.ifError(er) | ||
markdownpdf().from.paths(files).to.paths([tmpPdfPath0, tmpPdfPath1], function (er) { | ||
t.ifError(er) | ||
// Read the file | ||
var content0 = fs.readFileSync(tmpPdfPath0, {encoding: "utf8"}) | ||
var content1 = fs.readFileSync(tmpPdfPath1, {encoding: "utf8"}) | ||
// Read the file | ||
var content0 = fs.readFileSync(tmpPdfPath0, {encoding: "utf8"}) | ||
var content1 = fs.readFileSync(tmpPdfPath1, {encoding: "utf8"}) | ||
assert.ok(content0.length > 0) | ||
assert.ok(content1.length > 0) | ||
assert.ok(content0.length != content1.length) | ||
t.ok(content0.length > 0) | ||
t.ok(content1.length > 0) | ||
t.ok(content0.length != content1.length) | ||
done() | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
4
4
1
245371
1447
+ Addedthrough2@^0.6.3
+ Addedthrough2@0.6.5(transitive)
+ Addedtmp@0.0.24(transitive)
- Removedthrough@^2.3.4
- Removedthrough@2.3.8(transitive)
- Removedtmp@0.0.18(transitive)
Updatedphantomjs@^1.9.13
Updatedtmp@0.0.24