marked-terminal
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -34,4 +34,2 @@ # mversion [ <newversion> | major | minor | patch | prerelease ] [ -m <optional message> ] [ -n | --no-prefix ] | ||
`--tag` (or `-t` for short) allows for overriding the tag name used. | ||
@@ -67,2 +65,26 @@ This does not change behaviour of the message, just the tag name. | ||
## And a nested list | ||
* out A | ||
* out B | ||
* out C | ||
* out 1 | ||
* out 2 | ||
* out 2.1 | ||
* out 2.2 | ||
* out 2.2.1 | ||
* out 2.2.2 | ||
* out 2.2.3 | ||
* out 2.3 | ||
* out 3 | ||
* out 2.1 | ||
* out 2.2 | ||
Here are some `emojis`: :cake::tada: `some thing :smiley:` :cactus: :someundefined: | ||
And here are some proper emojis: 😀 | ||
Inside code blocks: | ||
``` | ||
var str = 'Some text :cake:'; | ||
``` |
76
index.js
@@ -5,4 +5,5 @@ "use strict"; | ||
var Table = require('cli-table'); | ||
var extend = require('node.extend'); | ||
var assign = require('lodash.assign'); | ||
var cardinal = require('cardinal'); | ||
var emoji = require('node-emoji'); | ||
@@ -14,2 +15,5 @@ | ||
var COLON_REPLACER = '*#COLON|*'; | ||
var COLON_REPLACER_REGEXP = new RegExp(escapeRegExp(COLON_REPLACER), 'g'); | ||
var defaultOptions = { | ||
@@ -32,2 +36,3 @@ code: chalk.yellow, | ||
unescape: true, | ||
emoji: true, | ||
tableOptions: {} | ||
@@ -37,5 +42,9 @@ }; | ||
function Renderer(options, highlightOptions) { | ||
this.o = extend(defaultOptions, options); | ||
this.o = assign({}, defaultOptions, options); | ||
this.tableSettings = this.o.tableOptions; | ||
this.emoji = this.o.emoji ? insertEmojis : identity; | ||
this.unescape = this.o.unescape ? unescapeEntities : identity; | ||
this.highlightOptions = highlightOptions || {}; | ||
this.transform = compose(undoColon, this.unescape, this.emoji); | ||
} | ||
@@ -56,4 +65,3 @@ | ||
Renderer.prototype.heading = function(text, level, raw) { | ||
var e = this.o.unescape ? unescapeEntities : identity; | ||
text = e(text); | ||
text = this.transform(text); | ||
@@ -72,29 +80,27 @@ var prefix = (new Array(level + 1)).join('#'); | ||
Renderer.prototype.list = function(body, ordered) { | ||
var e = this.o.unescape ? unescapeEntities : identity; | ||
if (ordered) { | ||
return changeToOrdered(e(body)) + '\n'; | ||
} | ||
return body + '\n'; | ||
body = indentLines(this.o.listitem(body)); | ||
if (!ordered) return body; | ||
return changeToOrdered(body); | ||
}; | ||
Renderer.prototype.listitem = function(text) { | ||
var e = this.o.unescape ? unescapeEntities : identity; | ||
return tab() + this.o.listitem('* ' + e(text)) + '\n'; | ||
var isNested = ~text.indexOf('\n'); | ||
if (isNested) text = text.trim(); | ||
return '\n * ' + this.transform(text); | ||
}; | ||
Renderer.prototype.paragraph = function(text) { | ||
var e = this.o.unescape ? unescapeEntities : identity; | ||
return this.o.paragraph(e(text)) + '\n\n'; | ||
var transform = compose(this.o.paragraph, this.transform); | ||
return transform(text) + '\n\n'; | ||
}; | ||
Renderer.prototype.table = function(header, body) { | ||
var e = this.o.unescape ? unescapeEntities : identity; | ||
var table = new Table(extend({ | ||
var table = new Table(assign({}, { | ||
head: generateTableRow(header)[0] | ||
}, this.tableSettings)); | ||
generateTableRow(body, e).forEach(function (row) { | ||
generateTableRow(body, this.transform).forEach(function (row) { | ||
table.push(row); | ||
}); | ||
return this.o.table(table.toString()) + '\n'; | ||
return this.o.table(table.toString()) + '\n\n'; | ||
}; | ||
@@ -120,3 +126,3 @@ | ||
Renderer.prototype.codespan = function(text) { | ||
return this.o.codespan(text); | ||
return this.o.codespan(text.replace(/:/g, COLON_REPLACER)); | ||
}; | ||
@@ -149,3 +155,3 @@ | ||
var out = ''; | ||
if (hasText) out += text + ' ('; | ||
if (hasText) out += this.emoji(text) + ' ('; | ||
out += this.o.href(href); | ||
@@ -165,2 +171,5 @@ if (hasText) out += ')'; | ||
function indentLines (text) { | ||
return text.replace(/\n/g, '\n' + tab()) + '\n\n'; | ||
} | ||
@@ -170,5 +179,5 @@ function changeToOrdered(text) { | ||
return text.split('\n').reduce(function (acc, line) { | ||
if (!line) return acc; | ||
return acc + tab() + (i++) + '.' + line.substring(tab().length + 1) + '\n'; | ||
}, ''); | ||
if (!line) return '\n' + acc; | ||
return acc + line.replace(/(\s*)\*/, '$1' + (i++) + '.') + '\n'; | ||
}); | ||
} | ||
@@ -188,2 +197,10 @@ | ||
function insertEmojis(text) { | ||
return text.replace(/:([A-Za-z0-9_\-\+]+?):/g, function (emojiString) { | ||
var emojiSign = emoji.get(emojiString); | ||
if (!emojiSign) return emojiString; | ||
return emojiSign + ' '; | ||
}); | ||
} | ||
function hr(inputHrStr) { | ||
@@ -198,2 +215,6 @@ return (new Array(process.stdout.columns)).join(inputHrStr); | ||
function undoColon (str) { | ||
return str.replace(COLON_REPLACER_REGEXP, ':'); | ||
} | ||
function indentify(text) { | ||
@@ -235,1 +256,12 @@ if (!text) return text; | ||
} | ||
function compose () { | ||
var funcs = arguments; | ||
return function() { | ||
var args = arguments; | ||
for (var i = funcs.length; i-- > 0;) { | ||
args = [funcs[i].apply(this, args)]; | ||
} | ||
return args[0]; | ||
}; | ||
} |
{ | ||
"name": "marked-terminal", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A custom render for marked to output to the Terminal", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha tests.js --reporter spec" | ||
"test": "mocha tests/*.js --reporter spec" | ||
}, | ||
@@ -19,9 +19,10 @@ "keywords": [ | ||
"peerDependencies": { | ||
"marked": "^0.3.2" | ||
"marked": "^0.3.3" | ||
}, | ||
"dependencies": { | ||
"cardinal": "^0.5.0", | ||
"chalk": "^0.5.1", | ||
"cli-table": "^0.3.0", | ||
"node.extend": "^1.0.10" | ||
"chalk": "^1.0.0", | ||
"cli-table": "^0.3.1", | ||
"lodash.assign": "^3.0.0", | ||
"node-emoji": "^0.1.0" | ||
}, | ||
@@ -32,4 +33,4 @@ "directories": { | ||
"devDependencies": { | ||
"marked": "^0.3.2", | ||
"mocha": "^1.21.4" | ||
"marked": "^0.3.3", | ||
"mocha": "^2.2.4" | ||
}, | ||
@@ -36,0 +37,0 @@ "repository": { |
@@ -94,2 +94,5 @@ marked-terminal | ||
// Whether or not to show emojis | ||
emoji: true, | ||
// Options passed to cli-table | ||
@@ -96,0 +99,0 @@ tableOptions: {} |
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
65592
13
340
116
6
+ Addedlodash.assign@^3.0.0
+ Addednode-emoji@^0.1.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedlodash._baseassign@3.2.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._bindcallback@3.0.1(transitive)
+ Addedlodash._createassigner@3.1.1(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.assign@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addednode-emoji@0.1.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removednode.extend@^1.0.10
- Removedansi-regex@0.2.1(transitive)
- Removedansi-styles@1.1.0(transitive)
- Removedchalk@0.5.1(transitive)
- Removedhas@1.0.4(transitive)
- Removedhas-ansi@0.1.0(transitive)
- Removedis@3.3.0(transitive)
- Removednode.extend@1.1.8(transitive)
- Removedstrip-ansi@0.3.0(transitive)
- Removedsupports-color@0.2.0(transitive)
Updatedchalk@^1.0.0
Updatedcli-table@^0.3.1