Comparing version 0.1.1 to 0.1.2
@@ -6,6 +6,12 @@ var parse = require('./lib/parse') | ||
var hermit = module.exports = function hermit(html, cb) { | ||
parse(html, { html: true }, function (err, res) { | ||
var layedout = layout(res) | ||
, styled = style(layedout) | ||
var hermit = module.exports = function hermit(html, opts, cb) { | ||
console.log('running hermit'); | ||
if (!cb) { | ||
cb = opts; | ||
opts = {}; | ||
} | ||
parse(html, opts, function (err, res) { | ||
var layedout = layout(res, opts) | ||
, styled = style(layedout, opts) | ||
, rendered = render(styled); | ||
@@ -19,5 +25,5 @@ | ||
// Expose helper libraries | ||
module.exports.parse = parse; | ||
module.exports.layout = layout; | ||
module.exports.style = style; | ||
module.exports.render = render; | ||
hermit.parse = parse; | ||
hermit.layout = layout; | ||
hermit.style = style; | ||
hermit.render = render; |
@@ -20,4 +20,2 @@ 'use strict'; | ||
if (!opts.hasOwnProperty('html')) opts.html = true; | ||
// s = s.replace(/([^\\]?)\n/g, '$1'); | ||
@@ -24,0 +22,0 @@ var parser = sax.parser(opts.html, { trim: false }) |
@@ -18,3 +18,2 @@ 'use strict'; | ||
try { | ||
console.log('trying', s); | ||
return cardinal.highlight(s, { linenos: false }); | ||
@@ -55,17 +54,1 @@ } catch (e) { | ||
}; | ||
/*var parse = require('./parse'); | ||
var render = require('./render'); | ||
var layout = require('./layout'); | ||
var html = [ | ||
].join('\n'); | ||
function inspect(obj, depth) { | ||
console.log(require('util').inspect(obj, false, depth || 5, true)); | ||
} | ||
var parsed = parse(html, function (err, res) { | ||
console.log(render(style(res))); | ||
inspect(render(style(res))); | ||
});*/ |
{ | ||
"name": "hermit", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Prints html in the terminal using colors and simple layout to reflect the document structure.", | ||
@@ -5,0 +5,0 @@ "main": "hermit.js", |
@@ -30,1 +30,19 @@ # hermit [![build status](https://secure.travis-ci.org/thlorenz/hermit.png)](http://next.travis-ci.org/thlorenz/hermit) | ||
#### Custom Options | ||
In order to affect the way that the printed html is layed out and styled, you can pass in custom properties. | ||
These include a stylesheet with the properties outined in the [default hermit | ||
stylesheet](https://github.com/thlorenz/hermit/blob/master/lib/stylesheet.js). | ||
```js | ||
var hermit = require('hermit'); | ||
, html = '<div><h3>Hello from Hermit</h3><p>A little paragraph for you</p></div>'; | ||
, myStylesheet = require('./path/to/my/stylesheet.js'); | ||
hermit(html, { listIndent: ' ', stylesheet: myStylesheet }, function (err, res) { | ||
console.log(res); | ||
}); | ||
``` | ||
For more information a detailed example read this [hermit test](https://github.com/thlorenz/hermit/blob/master/test/hermit.js#L11-L51) |
@@ -6,1 +6,55 @@ 'use strict'; | ||
, hermit = require('..') | ||
function inspect(obj, depth) { | ||
return require('util').inspect(obj, false, depth || 5, true); | ||
} | ||
+function integration() { | ||
var html = [ | ||
'<h2>outside</h2>' | ||
, '<ul>' | ||
, ' <li>' | ||
, ' <p>- One Level List</p>' | ||
, ' <ul>' | ||
, ' <li>' | ||
, ' <p>- Two Levels List</p>' | ||
, ' </li>' | ||
, ' </ul>' | ||
, ' </li>' | ||
, '</ul>' | ||
].join('\n') | ||
, stylesheet = { | ||
h1 : 'bgYellow blue' | ||
, h2 : 'bgGreen red' | ||
, h3 : 'underline blue' | ||
, h4 : 'underline' | ||
, h5 : 'underline brightBlack' | ||
, code: 'bgWhite black' | ||
, parent : { | ||
li: 'brightBlack' | ||
} | ||
} | ||
, expected = | ||
'\u001b[31m\u001b[42m\n\noutside\u001b[49m\u001b[39m\n' | ||
+ '##\u001b[90m- One Level List\u001b[39m\n\n' | ||
+ '####\u001b[90m- Two Levels List\u001b[39m\n\n'; | ||
test( 'given stylesheet\n' + inspect(stylesheet) | ||
+ '\nconverting\n' + html | ||
+ '\n\nreturns:\n' + expected | ||
, function (t) { | ||
hermit(html, { listIndent: '##', stylesheet: stylesheet }, function (err, res) { | ||
t.equals(res, expected, 'parses, lays out, styles and renders correctly') | ||
t.end() | ||
}) | ||
}) | ||
}(); | ||
test('exports', function (t) { | ||
t.equals(hermit.parse.toString(), require('../lib/parse').toString(), 'exports parse') | ||
t.equals(hermit.layout.toString(), require('../lib/layout').toString(), 'exports layout') | ||
t.equals(hermit.style.toString(), require('../lib/style').toString(), 'exports style') | ||
t.equals(hermit.render.toString(), require('../lib/render').toString(), 'exports render') | ||
t.end() | ||
}) |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var src = [ | ||
'<p>outside</p>' | ||
'<h2>outside</h2>' | ||
, '<ul>' | ||
@@ -30,11 +30,5 @@ , ' <li>' | ||
parse(src, function (err, res) { | ||
var expected = [ | ||
'' | ||
, 'outside' | ||
, '12- One Level List' | ||
, '' | ||
, '1212- Two Levels List' | ||
, '' | ||
, '' | ||
].join('\n') | ||
var expected = | ||
'\n\noutside\n12- One Level List\n' | ||
+ '\n1212- Two Levels List\n\n' | ||
, layedout = layout(res, { listIndent: '12' }) | ||
@@ -50,11 +44,5 @@ , result = render(layedout) | ||
parse(src, function (err, res) { | ||
var expected = [ | ||
'' | ||
, 'outside' | ||
, '1234- One Level List' | ||
, '' | ||
, '12341234- Two Levels List' | ||
, '' | ||
, '' | ||
].join('\n') | ||
var expected = | ||
'\n\noutside\n1234- One Level List\n' | ||
+ '\n12341234- Two Levels List\n\n' | ||
, layedout = layout(res, { listIndent: '1234' }) | ||
@@ -61,0 +49,0 @@ , result = render(layedout) |
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
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
35615
569
48