pygmentize-bundled
Advanced tools
Comparing version 2.2.0 to 2.3.0-pre1
20
index.js
const spawn = require('child_process').spawn | ||
, exec = require('child_process').exec | ||
, path = require('path') | ||
, fs = require('fs') | ||
, PassThrough = require('readable-stream/passthrough') | ||
, mkdirp = require('mkdirp') | ||
, bl = require('bl') | ||
@@ -14,4 +11,6 @@ , through2 = require('through2') | ||
var pythonVersions = {} | ||
function fromString (child, code, callback) { | ||
@@ -61,2 +60,3 @@ var stdout = bl() | ||
function pygmentize (options, code, callback) { | ||
@@ -81,6 +81,11 @@ options = options || {} | ||
spawnPygmentize(options, execArgs, function (err, child) { | ||
if (toString) { | ||
if (err) | ||
return callback(err) | ||
return fromString(child, code, callback) | ||
} | ||
// else stream | ||
if (err) | ||
return callback(err) | ||
if (toString) | ||
return fromString(child, code, callback) | ||
return retStream.emit('error', err) | ||
fromStream(retStream, intStream, child) | ||
@@ -99,2 +104,3 @@ }) | ||
function spawnPygmentize (options, execArgs, callback) { | ||
@@ -120,2 +126,3 @@ var python = typeof options.python == 'string' ? options.python : 'python' | ||
function pythonVersion (python, callback) { | ||
@@ -141,2 +148,3 @@ if (pythonVersions[python]) | ||
module.exports = pygmentize |
{ | ||
"name": "pygmentize-bundled", | ||
"version": "2.2.0", | ||
"version": "2.3.0-pre1", | ||
"description": "A simple wrapper around Python's Pygments code formatter, with Pygments bundled", | ||
@@ -29,4 +29,2 @@ "main": "index.js", | ||
"dependencies": { | ||
"mkdirp": "~0.3.5", | ||
"readable-stream": "~1.0.17", | ||
"bl": "~0.4.1", | ||
@@ -36,5 +34,5 @@ "through2": "~0.2.1" | ||
"devDependencies": { | ||
"stream-equal": ">= 0.0.1", | ||
"tape": "*" | ||
"stream-equal": "~0.1.5", | ||
"tape": "~3.0.3" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # Pygmentize (Bundled) | ||
[![NPM](https://nodei.co/npm/pygmentize-bundled.png?downloads=true&stars=true)](https://nodei.co/npm/pygmentize-bundled/) [![NPM](https://nodei.co/npm-dl/pygmentize-bundled.png?months=6)](https://nodei.co/npm/pygmentize-bundled/) | ||
[![NPM](https://nodei.co/npm/pygmentize-bundled.png?downloads=true&stars=true&downloadRank=true)](https://nodei.co/npm/pygmentize-bundled/) [![NPM](https://nodei.co/npm-dl/pygmentize-bundled.png?months=6&height=3)](https://nodei.co/npm/pygmentize-bundled/) | ||
@@ -12,2 +12,4 @@ Can be used as either a *String-in, Buffer-out*, or as a Duplex stream. | ||
**Note**: this library makes use of a child process which calls Python to invoke Pygments. This can cause performance problems where a large number of code blocks are being separately formatted. Consider using **[pygmentize-bundled-cached](https://github.com/rvagg/pygmentize-bundled-cached)**, an API-compatible wrapper for this library that keeps an on-disk cache of formatted code samples which will result in significantly faster formats when repeatedly formatting the same blocks of code. | ||
## API | ||
@@ -14,0 +16,0 @@ |
160
test.js
@@ -1,2 +0,2 @@ | ||
const tape = require('tape') | ||
const test = require('tape') | ||
, pygments = require('./') | ||
@@ -7,89 +7,99 @@ , fs = require('fs') | ||
function simpleStringConversionTest (python) { | ||
return function (t) { | ||
var cases = [ | ||
function createTests (test, pygments) { | ||
function simpleStringConversionTest (python) { | ||
return function (t) { | ||
var cases = [ | ||
{ | ||
lang: 'js' | ||
, format: 'html' | ||
, input: 'var a = "b";' | ||
, output: '<div class="highlight"><pre><span class="kd">var</span> <span class="nx">a</span> ' | ||
+ '<span class="o">=</span> <span class="s2">"b"</span><span class="p">;</span></pre></div>' | ||
} | ||
, { | ||
lang: 'c++' | ||
, format: 'console' | ||
, input: 'bool a = true;' | ||
, output: '\u001b[36mbool\u001b[39;49;00m \u001b[39;49;00ma\u001b[39;49;00m ' | ||
+ '\u001b[39;49;00m=\u001b[39;49;00m \u001b[39;49;00m\u001b[36mtrue\u001b[39;49;00m;\u001b[39;49;00m' | ||
} | ||
, { | ||
lang: 'php' | ||
, format: 'html' | ||
, input: 'var a = true;' | ||
, output: '<div class="highlight"><pre><span class="x">var a = true;</span></pre></div>' | ||
} | ||
, { | ||
lang: 'php' | ||
, format: 'html' | ||
, options: { startinline: 1 } | ||
, input: 'var a = true;' | ||
, output: '<div class="highlight"><pre><span class="k">var</span> <span class="nx">a</span> ' | ||
+ '<span class="o">=</span> <span class="k">true</span><span class="p">;</span></pre></div>' | ||
} | ||
] | ||
t.plan(cases.length * 3) | ||
cases.forEach(function (c) { | ||
pygments( | ||
{ | ||
lang: 'js' | ||
, format: 'html' | ||
, input: 'var a = "b";' | ||
, output: '<div class="highlight"><pre><span class="kd">var</span> <span class="nx">a</span> ' | ||
+ '<span class="o">=</span> <span class="s2">"b"</span><span class="p">;</span></pre></div>' | ||
lang : c.lang | ||
, format : c.format | ||
, options : c.options || {} | ||
, python : python | ||
} | ||
, { | ||
lang: 'c++' | ||
, format: 'console' | ||
, input: 'bool a = true;' | ||
, output: '\u001b[36mbool\u001b[39;49;00m \u001b[39;49;00ma\u001b[39;49;00m ' | ||
+ '\u001b[39;49;00m=\u001b[39;49;00m \u001b[39;49;00m\u001b[36mtrue\u001b[39;49;00m;\u001b[39;49;00m' | ||
, c.input | ||
, function (err, result) { | ||
t.equal(err, null) | ||
t.ok(Buffer.isBuffer(result), 'isBuffer') | ||
result = result.toString().replace(/\n/g, '') | ||
t.equal(result, c.output) | ||
} | ||
, { | ||
lang: 'php' | ||
, format: 'html' | ||
, input: 'var a = true;' | ||
, output: '<div class="highlight"><pre><span class="x">var a = true;</span></pre></div>' | ||
} | ||
, { | ||
lang: 'php' | ||
, format: 'html' | ||
, options: { startinline: 1 } | ||
, input: 'var a = true;' | ||
, output: '<div class="highlight"><pre><span class="k">var</span> <span class="nx">a</span> ' | ||
+ '<span class="o">=</span> <span class="k">true</span><span class="p">;</span></pre></div>' | ||
} | ||
] | ||
t.plan(cases.length * 3) | ||
cases.forEach(function (c) { | ||
pygments( | ||
{ | ||
lang : c.lang | ||
, format : c.format | ||
, options : c.options || {} | ||
, python : python | ||
} | ||
, c.input | ||
, function (err, result) { | ||
t.equal(err, null) | ||
t.ok(Buffer.isBuffer(result), 'isBuffer') | ||
result = result.toString().replace(/\n/g, '') | ||
t.equal(result, c.output) | ||
} | ||
) | ||
}) | ||
) | ||
}) | ||
} | ||
} | ||
} | ||
function fileConversionTest (python) { | ||
return function (t) { | ||
t.plan(2) | ||
function fileConversionTest (python) { | ||
return function (t) { | ||
t.plan(2) | ||
var fileIn = fs.createReadStream(__dirname + '/test-fixtures/active_model.rb') | ||
, fileOut = fs.createWriteStream( | ||
__dirname + '/test-fixtures/active_model.tmp' | ||
, { flags: 'w+', encoding: null, mode: 0666 } | ||
) | ||
var fileIn = fs.createReadStream(__dirname + '/test-fixtures/active_model.rb') | ||
, fileOut = fs.createWriteStream( | ||
__dirname + '/test-fixtures/active_model.tmp' | ||
, { flags: 'w+', encoding: null, mode: 0666 } | ||
) | ||
fileIn.pipe(pygments({ lang: 'rb', format: 'html', python: python })).pipe(fileOut) | ||
fileIn.pipe(pygments({ lang: 'rb', format: 'html', python: python })).pipe(fileOut) | ||
fileOut.on('close', function() { | ||
var expectedResult = fs.createReadStream(path.join(__dirname, '/test-fixtures/active_model.html')) | ||
, result = fs.createReadStream(path.join(__dirname, '/test-fixtures/active_model.tmp')) | ||
fileOut.on('close', function() { | ||
var expectedResult = fs.createReadStream(path.join(__dirname, '/test-fixtures/active_model.html')) | ||
, result = fs.createReadStream(path.join(__dirname, '/test-fixtures/active_model.tmp')) | ||
streamEqual(expectedResult, result, function (err, equal) { | ||
t.notOk(err, 'no error') | ||
t.ok(equal, 'stream equal') | ||
streamEqual(expectedResult, result, function (err, equal) { | ||
t.notOk(err, 'no error') | ||
t.ok(equal, 'stream equal') | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
test('simple string conversions', simpleStringConversionTest()) | ||
test('file conversions', fileConversionTest()) | ||
if (fs.existsSync('/usr/bin/python3')) { | ||
test('simple string conversions (python3)', simpleStringConversionTest('/usr/bin/python3')) | ||
test('file conversions (python3)', fileConversionTest('/usr/bin/python3')) | ||
} else { | ||
console.error('NO /usr/bin/python3, not testing Python3') | ||
} | ||
} | ||
tape('simple string conversions', simpleStringConversionTest()) | ||
tape('file conversions', fileConversionTest()) | ||
if (fs.existsSync('/usr/bin/python3')) { | ||
tape('simple string conversions (python3)', simpleStringConversionTest('/usr/bin/python3')) | ||
tape('file conversions (python3)', fileConversionTest('/usr/bin/python3')) | ||
} else { | ||
console.error('NO /usr/bin/python3, not testing Python3') | ||
} | ||
module.exports = createTests | ||
if (require.main === module) | ||
createTests(test, pygments) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
8378548
2
460
0
97
2
2
- Removedmkdirp@~0.3.5
- Removedreadable-stream@~1.0.17
- Removedmkdirp@0.3.5(transitive)