diff --git a/index.js b/index.js index 021a4bf..c2debf4 100644 --- a/index.js +++ b/index.js @@ -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 = '*|*|*|*'; @@ -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); }; diff --git a/package-lock.json b/package-lock.json index f8f3720..2913267 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,11 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "ansi-escapes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==" + }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -292,6 +297,22 @@ } } }, + "supports-hyperlinks": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-1.0.1.tgz", + "integrity": "sha512-HHi5kVSefKaJkGYXbDuKbUGRVxqnWGn3J2e39CYcNJEfWciGq2zYtOhXLTlvrOZW1QU7VX67w7fMmWafHX9Pfw==", + "requires": { + "has-flag": "^2.0.0", + "supports-color": "^5.0.0" + }, + "dependencies": { + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + } + } + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 75a93a1..3e4f6cf 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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"