hermit
Version:
Prints html in the terminal using colors and simple layout to reflect the document structure.
73 lines (64 loc) • 2.39 kB
JavaScript
;
/*jshint asi: true */
var parse = require('../lib/parse')
, layout = require('../lib/layout')
, render = require('../lib/render')
, style = require('../lib/style')
, test = require('tape')
var stylesheet = {
h1 : 'bgYellow blue'
, h2 : 'bgGreen blue'
, h3 : 'underline blue'
, h4 : 'underline'
, h5 : 'underline brightBlack'
, code: 'bgWhite black'
, parent : {
li: 'brightBlack'
}
};
function check(title, html, expected) {
test('\n# when parsing ' + title + '\n' + html + '\nand styling it, it renders as\n' + expected, function (t) {
parse(html, function (err, res) {
var styled = render(style(res, { stylesheet: stylesheet }))
// console.log(styled)
t.equals(styled, expected, 'correctly styled and rendered')
t.end()
})
})
}
+function headings() {
var html = [
'<html>'
, ' <h1>H1 Hello World</h1>'
, ' <h2>H2 Hello World</h2>'
, ' <h3>H3 Hello World</h3>'
, ' <h4>H4 Hello World</h4>'
, ' <h5>H5 Hello World</h5>'
, '</html>'
].join('\n')
, expected =
'\u001b[34m\u001b[43mH1 Hello World\u001b[49m\u001b[39m'
+ '\u001b[34m\u001b[42mH2 Hello World\u001b[49m\u001b[39m'
+ '\u001b[34m\u001b[4mH3 Hello World\u001b[24m\u001b[39m'
+ '\u001b[4mH4 Hello World\u001b[24m'
+ '\u001b[90m\u001b[4mH5 Hello World\u001b[24m\u001b[39m'
check('headings', html, expected)
}();
+function code_p() {
var html = '<p>Here is some unparseable code: <code>var a 3</code></p>'
, expected = 'Here is some unparseable code: \u001b[30m\u001b[47mvar a 3\u001b[49m\u001b[39m'
check('code inside <p>', html, expected)
}();
+function code_li_p() {
var html = '<li><p>Here is some unparseable code: <code>var a 3</code> that you should read</p></li>'
, expected =
'\u001b[90mHere is some unparseable code: \u001b[39m'
+ '\u001b[30m\u001b[47mvar a 3\u001b[49m\u001b[39m'
+ '\u001b[90m that you should read\u001b[39m'
check('code inside <li><p>', html, expected)
}();
+function code_parseable_p() {
var html = '<p>Here is some parseable code: <code>var a = 3;</code></p>'
, expected = 'Here is some parseable code: \u001b[32mvar\u001b[39m \u001b[37ma\u001b[39m \u001b[93m=\u001b[39m \u001b[34m3\u001b[39m\u001b[90m;\u001b[39m'
check('parseable code inside <p> is syntax highlighted', html, expected)
}();