Skip to content

Commit

Permalink
Merge pull request #52 from horosgrisa/master
Browse files Browse the repository at this point in the history
Add support for hyperlinks
  • Loading branch information
mikaelbr authored Jan 10, 2019
2 parents 0e48205 + 66570ac commit 8b7c66e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ var chalk = require('chalk');
var Table = require('cli-table');
var cardinal = require('cardinal');
var emoji = require('node-emoji');
const ansiEscapes = require('ansi-escapes');
const supportsHyperlinks = require('supports-hyperlinks');


var TABLE_CELL_SPLIT = '^*||*^';
var TABLE_ROW_WRAP = '*|*|*|*';
Expand Down Expand Up @@ -193,10 +196,14 @@ Renderer.prototype.link = function(href, title, text) {
var hasText = text && text !== href;

var out = '';
if (hasText) out += this.emoji(text) + ' (';
out += this.o.href(href);
if (hasText) out += ')';

if (supportsHyperlinks.stdout) {
out = ansiEscapes.link(text?this.emoji(text):href, href);
}else{
if (hasText) out += this.emoji(text) + ' (';
out += this.o.href(href);
if (hasText) out += ')';
}
return this.o.link(out);
};

Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A custom render for marked to output to the Terminal",
"main": "index.js",
"scripts": {
"test": "mocha tests/*.js --reporter spec"
"test": "FORCE_HYPERLINK=0 mocha tests/*.js --reporter spec"
},
"files": [
"index.js"
Expand All @@ -22,10 +22,12 @@
"marked": "^0.4.0 || ^0.5.0 || ^0.6.0"
},
"dependencies": {
"ansi-escapes": "^3.1.0",
"cardinal": "^2.1.1",
"chalk": "^2.4.1",
"cli-table": "^0.3.1",
"node-emoji": "^1.4.1"
"node-emoji": "^1.4.1",
"supports-hyperlinks": "^1.0.1"
},
"directories": {
"example": "example"
Expand Down

0 comments on commit 8b7c66e

Please sign in to comment.