Socket
Socket
Sign inDemoInstall

remark-github

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-github - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

9

history.md

@@ -7,2 +7,11 @@ <!--remark setext-->

4.0.0 / 2016-01-23
==================
* Add support for transforming links to references ([`bb00af7`](https://github.com/wooorm/remark-github/commit/bb00af7))
* Refactor `readme.md` ([`c9dd323`](https://github.com/wooorm/remark-github/commit/c9dd323))
* Update metadata in `package.json`, `component.json` ([`8ff5ee4`](https://github.com/wooorm/remark-github/commit/8ff5ee4))
* Add npm deployment to Travis ([`b098760`](https://github.com/wooorm/remark-github/commit/b098760))
* Update dev-dependencies ([`c408345`](https://github.com/wooorm/remark-github/commit/c408345))
3.0.0 / 2016-01-13

@@ -9,0 +18,0 @@ ==================

502

index.js

@@ -18,2 +18,9 @@ /**

/*
* Dependencies.
*/
var visit = require('unist-util-visit');
var toString = require('mdast-util-to-string');
/*
* Constants.

@@ -24,5 +31,8 @@ */

var GH_ISSUE_PREFIX = 'gh-';
var COMMITS = 'commit/';
var ISSUES = 'issues/';
var GH_URL_PREFIX = 'https://github.com/';
var MESSAGE_COMMENT = ' (comment)';
var EMPTY = '';
var GH_URL_PREFIX_LENGTH = GH_URL_PREFIX.length;
var MAX_SHA_LENGTH = 40;
var MINUSCULE_SHA_LENGTH = 4;
var MIN_SHA_LENGTH = 7;

@@ -59,2 +69,19 @@ var MAX_USER_LENGTH = 39;

/*
* Enum of known pages.
*/
var COMMIT = 'commit';
var ISSUE = 'issues';
var PULL = 'pull';
/*
* Node types.
*/
var T_INLINE_CODE = 'inlineCode';
var T_TEXT = 'text';
var T_STRONG = 'strong';
var T_LINK = 'link';
/*
* Blacklist of SHAs which are also valid words.

@@ -106,4 +133,4 @@ *

*/
function isSHA(sha) {
return BLACKLIST.indexOf(sha.toLowerCase()) === -1;
function isBlacklisted(sha) {
return BLACKLIST.indexOf(sha.toLowerCase()) !== -1;
}

@@ -118,3 +145,3 @@

function abbr(sha) {
return sha.slice(0, 7);
return sha.slice(0, MIN_SHA_LENGTH);
}

@@ -131,3 +158,3 @@

function gh(repo, project) {
var base = 'https://github.com/';
var base = GH_URL_PREFIX;

@@ -241,2 +268,144 @@ if (project) {

/**
* Get the end of a username which starts at character
* `fromIndex` in `value`.
*
* @param {string} value - Value to check.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - End position of username, or `-1`.
*/
function getUserNameEndPosition(value, fromIndex) {
var index = fromIndex;
var length = value.length;
var size;
/* First character of username cannot be a dash. */
if (value.charCodeAt(index) === CC_DASH) {
return -1;
}
while (index < length) {
if (!isValidUserNameCharacter(value.charCodeAt(index))) {
break;
}
index++;
}
size = index - fromIndex;
/* Last character of username cannot be a dash. */
if (
!size ||
size > MAX_USER_LENGTH ||
value.charCodeAt(index - 1) === CC_DASH
) {
return -1;
}
return index;
}
/**
* Get the end of a project which starts at character
* `fromIndex` in `value`.
*
* @param {string} value - Value to check.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - End position of project, or `-1`.
*/
function getProjectEndPosition(value, fromIndex) {
var index = fromIndex;
var length = value.length;
var size;
while (index < length) {
if (!isValidProjectNameCharacter(value.charCodeAt(index))) {
break;
}
index++;
}
size = fromIndex - index;
if (
!size ||
size > MAX_PROJECT_LENGTH ||
(value.slice(index - GIT_SUFFIX.length, index) === GIT_SUFFIX)
) {
return -1;
}
return index;
}
/**
* Get the end of a SHA which starts at character
* `fromIndex` in `value`.
*
* @param {string} value - Value to check.
* @param {number} fromIndex - Index to start searching at.
* @param {boolean} [allowShort=false] - Whether to allow
* extra short SHAs (4 characters instead of 7).
* @return {number} - End position of SHA, or `-1`.
*/
function getSHAEndPosition(value, fromIndex, allowShort) {
var index = fromIndex;
var length = value.length;
var size;
/* No reason walking too far. */
if (length > index + MAX_SHA_LENGTH) {
length = index + MAX_SHA_LENGTH;
}
while (index < length) {
if (!isHexadecimal(value.charCodeAt(index))) {
break;
}
index++;
}
size = index - fromIndex;
if (
size < (allowShort ? MINUSCULE_SHA_LENGTH : MIN_SHA_LENGTH) ||
(size === MAX_SHA_LENGTH && isHexadecimal(value.charCodeAt(index)))
) {
return -1;
}
return index;
}
/**
* Get the end of an issue which starts at character
* `fromIndex` in `value`.
*
* @param {string} value - Value to check.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - End position of issue, or `-1`.
*/
function getIssueEndPosition(value, fromIndex) {
var index = fromIndex;
var length = value.length;
while (index < length) {
if (!isDecimal(value.charCodeAt(index))) {
break;
}
index++;
}
if (index - fromIndex === 0) {
return -1;
}
return index;
}
/**
* Create a bound regex locator.

@@ -306,4 +475,3 @@ *

var self = this;
var index = 0;
var length = value.length;
var index = getSHAEndPosition(value, 0);
var subvalue;

@@ -314,18 +482,3 @@ var href;

if (length > MAX_SHA_LENGTH) {
length = MAX_SHA_LENGTH;
}
while (index < length) {
if (!isHexadecimal(value.charCodeAt(index))) {
break;
}
index++;
}
if (
index < MIN_SHA_LENGTH ||
(index === length && isHexadecimal(value.charCodeAt(index)))
) {
if (index === -1) {
return;

@@ -336,3 +489,3 @@ }

if (!isSHA(subvalue)) {
if (isBlacklisted(subvalue)) {
return;

@@ -346,3 +499,3 @@ }

href = gh(self.github) + 'commit/' + subvalue;
href = gh(self.github) + COMMIT + C_SLASH + subvalue;
now = eat.now();

@@ -355,3 +508,3 @@

node.children = [{
'type': 'inlineCode',
'type': T_INLINE_CODE,
'value': abbr(subvalue),

@@ -406,5 +559,2 @@ 'position': node.children[0].position

var index;
var length;
var slash;
var code;
var subvalue;

@@ -416,43 +566,24 @@ var handle;

if (
value.charCodeAt(0) !== CC_AT ||
value.charCodeAt(1) === CC_DASH
) {
if (value.charCodeAt(0) !== CC_AT) {
return;
}
slash = -1;
length = value.length;
index = 1;
index = getUserNameEndPosition(value, 1);
while (index < length) {
code = value.charCodeAt(index);
if (index === -1) {
return;
}
if (code === CC_SLASH) {
if (slash !== -1) {
break;
}
/*
* Support teams.
*/
slash = index;
if (value.charCodeAt(index) === CC_SLASH) {
index = getUserNameEndPosition(value, index + 1);
if (
value.charCodeAt(index - 1) === CC_DASH ||
value.charCodeAt(index + 1) === CC_DASH
) {
return;
}
} else if (!isValidUserNameCharacter(code)) {
break;
if (index === -1) {
return;
}
index++;
}
if (
value.charCodeAt(index - 1) === CC_DASH ||
index > MAX_USER_LENGTH + 1
) {
return;
}
/* istanbul ignore if - maybe used by plug-ins */

@@ -477,3 +608,3 @@ if (silent) {

node.children = [{
'type': 'strong',
'type': T_STRONG,
'children': node.children

@@ -505,3 +636,2 @@ }];

var index;
var length;
var start;

@@ -524,13 +654,5 @@ var subvalue;

start = index;
length = value.length;
index = getIssueEndPosition(value, index);
while (index < length) {
if (!isDecimal(value.charCodeAt(index))) {
break;
}
index++;
}
if (index === start) {
if (index === -1) {
return;

@@ -545,3 +667,3 @@ }

now = eat.now();
href = gh(self.github) + ISSUES + value.slice(start, index);
href = gh(self.github) + ISSUE + C_SLASH + value.slice(start, index);
subvalue = value.slice(0, index);

@@ -631,3 +753,2 @@

var index = 0;
var length = value.length;
var code;

@@ -649,45 +770,17 @@ var handle;

/* First character of username cannot be a dash. */
if (value.charCodeAt(index) === CC_DASH) {
return;
}
index = getUserNameEndPosition(value, index);
while (index < length) {
if (!isValidUserNameCharacter(value.charCodeAt(index))) {
break;
}
index++;
}
/* Last character of username cannot be a dash. */
if (value.charCodeAt(index - 1) === CC_DASH) {
if (index === -1) {
return;
}
handleEnd = index;
code = value.charCodeAt(index);
/* Last character of username cannot be a dash. */
if (!index || index > MAX_USER_LENGTH) {
return;
}
handleEnd = index;
if (code === CC_SLASH) {
index++;
projectStart = index;
index = getProjectEndPosition(value, projectStart);
while (index < length) {
if (!isValidProjectNameCharacter(value.charCodeAt(index))) {
break;
}
index++;
}
if (
(index - projectStart) > MAX_PROJECT_LENGTH ||
(value.slice(index - GIT_SUFFIX.length, index) === GIT_SUFFIX)
) {
if (index === -1) {
return;

@@ -697,12 +790,11 @@ }

projectEnd = index;
code = value.charCodeAt(projectEnd);
}
code = value.charCodeAt(index);
if (code === CC_HASH) {
test = isDecimal;
suffix = ISSUES;
suffix = ISSUE;
test = getIssueEndPosition;
} else if (code === CC_AT) {
test = isHexadecimal;
suffix = COMMITS;
suffix = COMMIT;
test = getSHAEndPosition;
} else {

@@ -716,31 +808,10 @@ return;

while (index < length) {
if (!test(value.charCodeAt(index))) {
if (isValidUserNameCharacter(value.charCodeAt(index))) {
return;
}
index = test(value, referenceStart);
break;
}
index++;
if (index === -1 || isValidUserNameCharacter(value.charCodeAt(index))) {
return;
}
reference = value.slice(referenceStart, index);
content = reference;
content = reference = value.slice(referenceStart, index);
if (
suffix === COMMITS &&
(
reference.length < MIN_SHA_LENGTH ||
reference.length > MAX_SHA_LENGTH
)
) {
reference = null;
}
if (!reference) {
return;
}
/* istanbul ignore if - maybe used by plug-ins */

@@ -753,12 +824,13 @@ if (silent) {

project = projectEnd && value.slice(projectStart, projectEnd);
href = gh(handle, project || self.github.project) + suffix + reference;
href = gh(handle, project || self.github.project);
subvalue = value.slice(0, index);
handle += (project ? C_SLASH + project : '') + delimiter;
handle += (project ? C_SLASH + project : EMPTY) + delimiter;
add = eat(subvalue);
href += suffix + C_SLASH + reference;
if (suffix === COMMITS) {
if (suffix === COMMIT) {
node = add(self.renderLink(true, href, handle, null, now, eat));
node.children.push({
'type': 'inlineCode',
'type': T_INLINE_CODE,
'value': abbr(content)

@@ -777,2 +849,75 @@ });

/**
* Parse a link and determine whether it links to GitHub.
*
* @param {LinkNode} node - Link node.
* @return {Object?} - Information.
*/
function parseLink(node) {
var link = {};
var url = node.href;
var start;
var end;
var page;
if (
url.slice(0, GH_URL_PREFIX_LENGTH) !== GH_URL_PREFIX ||
node.children.length !== 1 ||
node.children[0].type !== T_TEXT ||
toString(node).slice(0, GH_URL_PREFIX_LENGTH) !== GH_URL_PREFIX
) {
return;
}
start = GH_URL_PREFIX_LENGTH;
end = getUserNameEndPosition(url, GH_URL_PREFIX_LENGTH);
if (end === -1 || url.charCodeAt(end) !== CC_SLASH) {
return;
}
link.user = url.slice(start, end);
start = end + 1;
end = getUserNameEndPosition(url, start);
if (end === -1 || url.charCodeAt(end) !== CC_SLASH) {
return;
}
link.project = url.slice(start, end);
start = end + 1;
end = url.indexOf(C_SLASH, start);
if (end === -1) {
return;
}
page = url.slice(start, end);
if (page !== COMMIT && page !== ISSUE && page !== PULL) {
return;
}
link.page = page;
start = end + 1;
if (page === COMMIT) {
end = getSHAEndPosition(url, start, true);
} else {
end = getIssueEndPosition(url, start);
}
if (end === -1) {
return;
}
link.reference = url.slice(start, end);
link.comment = url.charCodeAt(end) === CC_HASH &&
url.length > end + 1;
return link;
}
/**
* Attacher.

@@ -782,2 +927,3 @@ *

* @param {Object?} [options] - Configuration.
* @return {Function} - Transformer.
*/

@@ -804,3 +950,7 @@ function attacher(remark, options) {

repo = pack.repository ? pack.repository.url || pack.repository : '';
if (pack.repository) {
repo = pack.repository.url || pack.repository;
} else {
repo = EMPTY;
}
}

@@ -847,2 +997,66 @@

);
/**
* Transformer.
*
* @param {Node} tree - Root node.
*/
function transformer(tree) {
visit(tree, T_LINK, function (node) {
var link = parseLink(node);
var children;
var base;
var comment;
if (!link) {
return;
}
comment = link.comment ? MESSAGE_COMMENT : EMPTY;
if (link.project !== repo.project) {
base = link.user + C_SLASH + link.project;
} else if (link.user !== repo.user) {
base = link.user;
} else {
base = EMPTY;
}
if (link.page !== COMMIT) {
base += C_HASH;
children = [
{
'type': T_TEXT,
'value': base + abbr(link.reference) + comment
}
];
} else {
children = [];
if (base) {
children.push({
'type': T_TEXT,
'value': base + C_AT
});
}
children.push({
'type': T_INLINE_CODE,
'value': abbr(link.reference)
});
if (link.comment) {
children.push({
'type': T_TEXT,
'value': comment
});
}
}
node.children = children;
});
}
return transformer;
}

@@ -849,0 +1063,0 @@

{
"name": "remark-github",
"version": "3.0.0",
"version": "4.0.0",
"description": "Auto-link references like in GitHub issues, PRs, and comments",

@@ -19,3 +19,7 @@ "license": "MIT",

],
"repository": "wooorm/remark-github",
"repository": {
"type": "git",
"url": "https://github.com/wooorm/remark-github.git"
},
"bugs": "https://github.com/wooorm/remark-github/issues",
"author": "Titus Wormer <tituswormer@gmail.com>",

@@ -25,4 +29,8 @@ "files": [

],
"dependencies": {
"mdast-util-to-string": "^1.0.1",
"unist-util-visit": "^1.0.0"
},
"devDependencies": {
"browserify": "^12.0.0",
"browserify": "^13.0.0",
"eslint": "^1.0.0",

@@ -29,0 +37,0 @@ "esmangle": "^1.0.0",

@@ -1,8 +0,9 @@

# remark-github [![Build Status](https://img.shields.io/travis/wooorm/remark-github.svg)](https://travis-ci.org/wooorm/remark-github) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/remark-github.svg)](https://codecov.io/github/wooorm/remark-github)
# remark-github [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
Auto-link references to commits, issues, pull-requests, and users like GitHub: [Writing on GitHub](https://help.github.com/articles/writing-on-github/#references).
Auto-link references to commits, issues, pull-requests, and users like
GitHub: [Writing on GitHub][writing-on-github].
## Installation
[npm](https://docs.npmjs.com/cli/install)
[npm][npm-install]:

@@ -13,16 +14,5 @@ ```bash

**remark-github** is also available for [duo](http://duojs.org/#getting-started),
and as an AMD, CommonJS, and globals module, [uncompressed and
compressed](https://github.com/wooorm/remark-github/releases).
**remark-github** is also available for [duo][duo-install], and as an
AMD, CommonJS, and globals module, [uncompressed and compressed][releases].
## Table of Contents
* [Usage](#usage)
* [API](#api)
* [remark.use(github, options)](#remarkusegithub-options)
* [License](#license)
## Usage

@@ -77,32 +67,32 @@

### [remark](https://github.com/wooorm/remark#api).[use](https://github.com/wooorm/remark#remarkuseplugin-options)(github, options)
### `remark.use(github[, options])`
Adds references to commits, issues, pull-requests, and users similar to how
[GitHub](https://help.github.com/articles/writing-on-github/#references)
[GitHub][writing-on-github]
renders these in issues, comments, and pull request descriptions.
* SHA commits references: `1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921`
— [`1f2a4fb`](https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921)
— [`1f2a4fb`][sha]
* User@SHA: `wooorm@1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921`
— [wooorm@`1f2a4fb`](https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921)
— [wooorm@`1f2a4fb`][user-sha]
* User/Repository@SHA:
`wooorm/remark-github@1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921`
— [wooorm/remark-github@`1f2a4fb`](https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921)
— [wooorm/remark-github@`1f2a4fb`][project-sha]
* Hash-Num: `#1`
— [#1](https://github.com/wooorm/remark-github/issues/1)
— [#1][issue]
* GH-Num: `GH-1`
— [GH-1](https://github.com/wooorm/remark-github/issues/1)
— [GH-1][issue]
* User#Num: `wooorm#1`
— [wooorm#1](https://github.com/wooorm/remark-github/issues/1)
— [wooorm#1][user-issue]
* User/Repository#Num: `wooorm/remark-github#1`
— [wooorm/remark-github#1](https://github.com/wooorm/remark-github/issues/1)
— [wooorm/remark-github#1][project-issue]
* At-mentions: `@mention` and `@wooorm`
— [**@mention**](https://github.com/blog/821) and [**@wooorm**](https://github.com/wooorm)
— [**@mention**][mentions] and [**@wooorm**][mention]

@@ -116,2 +106,40 @@ These links are generated relative to a project. In Node this is auto-detected

[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[travis-badge]: https://img.shields.io/travis/wooorm/remark-github.svg
[travis]: https://travis-ci.org/wooorm/remark-github
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/remark-github.svg
[codecov]: https://codecov.io/github/wooorm/remark-github
[npm-install]: https://docs.npmjs.com/cli/install
[duo-install]: http://duojs.org/#getting-started
[releases]: https://github.com/wooorm/remark-github/releases
[license]: LICENSE
[author]: http://wooorm.com
[writing-on-github]: https://help.github.com/articles/writing-on-github/#references
[sha]: https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921
[user-sha]: https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921
[project-sha]: https://github.com/wooorm/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921
[issue]: https://github.com/wooorm/remark-github/issues/1
[user-issue]: https://github.com/wooorm/remark-github/issues/1
[project-issue]: https://github.com/wooorm/remark-github/issues/1
[mentions]: https://github.com/blog/821
[mention]: https://github.com/wooorm
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc