Skip to content

Commit 8b7c66e

Browse files
authored
Merge pull request #52 from horosgrisa/master
Add support for hyperlinks
2 parents 0e48205 + 66570ac commit 8b7c66e

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ var chalk = require('chalk');
44
var Table = require('cli-table');
55
var cardinal = require('cardinal');
66
var emoji = require('node-emoji');
7+
const ansiEscapes = require('ansi-escapes');
8+
const supportsHyperlinks = require('supports-hyperlinks');
9+
710

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

195198
var out = '';
196-
if (hasText) out += this.emoji(text) + ' (';
197-
out += this.o.href(href);
198-
if (hasText) out += ')';
199199

200+
if (supportsHyperlinks.stdout) {
201+
out = ansiEscapes.link(text?this.emoji(text):href, href);
202+
}else{
203+
if (hasText) out += this.emoji(text) + ' (';
204+
out += this.o.href(href);
205+
if (hasText) out += ')';
206+
}
200207
return this.o.link(out);
201208
};
202209

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A custom render for marked to output to the Terminal",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha tests/*.js --reporter spec"
7+
"test": "FORCE_HYPERLINK=0 mocha tests/*.js --reporter spec"
88
},
99
"files": [
1010
"index.js"
@@ -22,10 +22,12 @@
2222
"marked": "^0.4.0 || ^0.5.0 || ^0.6.0"
2323
},
2424
"dependencies": {
25+
"ansi-escapes": "^3.1.0",
2526
"cardinal": "^2.1.1",
2627
"chalk": "^2.4.1",
2728
"cli-table": "^0.3.1",
28-
"node-emoji": "^1.4.1"
29+
"node-emoji": "^1.4.1",
30+
"supports-hyperlinks": "^1.0.1"
2931
},
3032
"directories": {
3133
"example": "example"

0 commit comments

Comments
 (0)