Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-github

Package Overview
Dependencies
Maintainers
2
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 11.2.4 to 12.0.0

lib/get-repo-from-package.default.d.ts

19

index.d.ts

@@ -1,11 +0,8 @@

export {default} from './lib/index.js'
export type Options = import('./lib/index.js').Options
export type BuildUrl = import('./lib/index.js').BuildUrl
export type DefaultBuildUrl = import('./lib/index.js').DefaultBuildUrl
export type BuildUrlValues = import('./lib/index.js').BuildUrlValues
export type BuildUrlCommitValues = import('./lib/index.js').BuildUrlCommitValues
export type BuildUrlCompareValues =
import('./lib/index.js').BuildUrlCompareValues
export type BuildUrlIssueValues = import('./lib/index.js').BuildUrlIssueValues
export type BuildUrlMentionValues =
import('./lib/index.js').BuildUrlMentionValues
export type BuildUrl = import('./lib/index.js').BuildUrl;
export type BuildUrlCommitValues = import('./lib/index.js').BuildUrlCommitValues;
export type BuildUrlCompareValues = import('./lib/index.js').BuildUrlCompareValues;
export type BuildUrlIssueValues = import('./lib/index.js').BuildUrlIssueValues;
export type BuildUrlMentionValues = import('./lib/index.js').BuildUrlMentionValues;
export type BuildUrlValues = import('./lib/index.js').BuildUrlValues;
export type Options = import('./lib/index.js').Options;
export { default, defaultBuildUrl } from "./lib/index.js";
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').BuildUrl} BuildUrl
* @typedef {import('./lib/index.js').DefaultBuildUrl} DefaultBuildUrl
* @typedef {import('./lib/index.js').BuildUrlValues} BuildUrlValues
* @typedef {import('./lib/index.js').BuildUrlCommitValues} BuildUrlCommitValues

@@ -10,4 +7,6 @@ * @typedef {import('./lib/index.js').BuildUrlCompareValues} BuildUrlCompareValues

* @typedef {import('./lib/index.js').BuildUrlMentionValues} BuildUrlMentionValues
* @typedef {import('./lib/index.js').BuildUrlValues} BuildUrlValues
* @typedef {import('./lib/index.js').Options} Options
*/
export {default} from './lib/index.js'
export {default, defaultBuildUrl} from './lib/index.js'
/**
* Plugin to autolink references like in GitHub issues, PRs, and comments.
* Create a URL to GH.
*
* @type {import('unified').Plugin<[Options?]|void[], Root>}
* @satisfies {BuildUrl}
* @param {Readonly<BuildUrlValues>} values
* Info on the link to build.
* @returns {string}
* URL to use.
*/
export default function remarkGithub(
options?: void | Options | undefined
):
| void
| import('unified').Transformer<import('mdast').Root, import('mdast').Root>
export type Root = import('mdast').Root
export type StaticPhrasingContent = import('mdast').StaticPhrasingContent
export type ReplaceFunction =
import('mdast-util-find-and-replace').ReplaceFunction
export type Match = {
input: string
index: number
}
export type DefaultBuildUrl = (values: BuildUrlValues) => string
export type BuildUrl = (
values: BuildUrlValues,
defaultBuildUrl: DefaultBuildUrl
) => string | false
export type BuildUrlValues =
| BuildUrlCommitValues
| BuildUrlCompareValues
| BuildUrlIssueValues
| BuildUrlMentionValues
export function defaultBuildUrl(values: Readonly<BuildUrlValues>): string;
/**
* Arguments for buildUrl functions for commit hash
* Link references to users, commits, and issues, in the same way that GitHub
* does in comments, issues, PRs, and releases.
*
* @param {Readonly<Options> | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export default function remarkGithub(options?: Readonly<Options> | null | undefined): (tree: Root, file: VFile) => undefined;
export type PhrasingContent = import('mdast').PhrasingContent;
export type Root = import('mdast').Root;
export type ReplaceFunction = import('mdast-util-find-and-replace').ReplaceFunction;
export type RegExpMatchObject = import('mdast-util-find-and-replace').RegExpMatchObject;
export type VFile = import('vfile').VFile;
/**
* Create a URL.
*/
export type BuildUrl = (values: Readonly<BuildUrlValues>) => string | false;
/**
* Info for commit hash.
*/
export type BuildUrlCommitValues = {
/**
* The type of special object
*/
type: 'commit'
/**
* The owner of the repo
*/
user: string
/**
* The project of the repo
*/
project: string
/**
* The commit hash value
*/
hash: string
}
/**
* Commit hash value.
*/
hash: string;
/**
* Project name.
*/
project: string;
/**
* Kind.
*/
type: 'commit';
/**
* Owner of repo.
*/
user: string;
};
/**
* Arguments for buildUrl functions for commit hash ranges
* Info for commit hash ranges.
*/
export type BuildUrlCompareValues = {
/**
* The type of special object
*/
type: 'compare'
/**
* The owner of the repo
*/
user: string
/**
* The project of the repo
*/
project: string
/**
* The SHA of the range start
*/
base: string
/**
* The SHA of the range end
*/
compare: string
}
/**
* SHA of the range start.
*/
base: string;
/**
* SHA of the range end.
*/
compare: string;
/**
* Project name.
*/
project: string;
/**
* Kind.
*/
type: 'compare';
/**
* Owner of repo.
*/
user: string;
};
/**
* Arguments for buildUrl functions for issues
* Info for issues.
*/
export type BuildUrlIssueValues = {
/**
* The type of special object
*/
type: 'issue'
/**
* The owner of the repo
*/
user: string
/**
* The project of the repo
*/
project: string
/**
* The parsed issue number
*/
no: string
}
/**
* Issue number.
*/
no: string;
/**
* Project name.
*/
project: string;
/**
* Kind.
*/
type: 'issue';
/**
* Owner of repo.
*/
user: string;
};
/**
* Arguments for buildUrl functions for mentions
* Info for mentions.
*/
export type BuildUrlMentionValues = {
/**
* The type of special object
*/
type: 'mention'
/**
* The parsed user name
*/
user: string
}
/**
* Kind.
*/
type: 'mention';
/**
* User name.
*/
user: string;
};
/**
* The owner and project of the repo
* Info.
*/
export type RepositoryInfo = {
/**
* The user/organization name
*/
user: string
/**
* The project/repo name
*/
project: string
}
export type BuildUrlValues = BuildUrlCommitValues | BuildUrlCompareValues | BuildUrlIssueValues | BuildUrlMentionValues;
/**

@@ -126,18 +118,55 @@ * Configuration.

export type Options = {
/**
* Repository to link against.
* Detected from the `repository` field in `package.json` if not given.
* Should point to a GitHub repository.
*/
repository?: string | undefined
/**
* Wrap mentions in `strong`.
* This makes them render more like how GitHub styles them.
* But GitHub itself uses CSS instead of strong.
*/
mentionStrong?: boolean | undefined
/**
* Change how (and whether) things are linked.
*/
buildUrl?: BuildUrl | undefined
}
/**
* Change how things are linked (optional).
*/
buildUrl?: BuildUrl | null | undefined;
/**
* Wrap mentions in `strong` (default: `true`);
* this makes them render more like how GitHub styles them, but GH itself
* uses CSS instead of `strong`.
*/
mentionStrong?: boolean | null | undefined;
/**
* Repository to link against (default: `repository` from `packag.json` in CWD in Node);
* should point to a GitHub repository (such as `'user/project'`)
*/
repository?: string | null | undefined;
};
/**
* Owner and project of repo.
*/
export type RepositoryInfo = {
/**
* Project name.
*/
project: string;
/**
* User/organization name.
*/
user: string;
};
/**
* Info.
*/
export type UrlInfo = {
/**
* Whether the link is to a comment.
*/
comment: boolean;
/**
* Page type.
*/
page: string;
/**
* Project name.
*/
project: string;
/**
* Reference.
*/
reference: string;
/**
* User/organization name.
*/
user: string;
};
/**
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').StaticPhrasingContent} StaticPhrasingContent
* @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
* @typedef {{input: string, index: number}} Match
*
* @callback DefaultBuildUrl
* @param {BuildUrlValues} values
* @returns {string}
*
* @typedef {import('mdast-util-find-and-replace').RegExpMatchObject} RegExpMatchObject
* @typedef {import('vfile').VFile} VFile
*/
/**
* @callback BuildUrl
* @param {BuildUrlValues} values
* Create a URL.
* @param {Readonly<BuildUrlValues>} values
* Info on the link to build.
* @param {DefaultBuildUrl} defaultBuildUrl
* Function that can be called to perform normal behavior.
* @returns {string|false}
* @returns {string | false}
* URL to use or `false` to not link.
*
* @typedef {BuildUrlCommitValues|BuildUrlCompareValues|BuildUrlIssueValues|BuildUrlMentionValues} BuildUrlValues
*
* @typedef BuildUrlCommitValues
* Arguments for buildUrl functions for commit hash
* @property {'commit'} type The type of special object
* @property {string} user The owner of the repo
* @property {string} project The project of the repo
* @property {string} hash The commit hash value
* Info for commit hash.
* @property {string} hash
* Commit hash value.
* @property {string} project
* Project name.
* @property {'commit'} type
* Kind.
* @property {string} user
* Owner of repo.
*
* @typedef BuildUrlCompareValues
* Arguments for buildUrl functions for commit hash ranges
* @property {'compare'} type The type of special object
* @property {string} user The owner of the repo
* @property {string} project The project of the repo
* @property {string} base The SHA of the range start
* @property {string} compare The SHA of the range end
* Info for commit hash ranges.
* @property {string} base
* SHA of the range start.
* @property {string} compare
* SHA of the range end.
* @property {string} project
* Project name.
* @property {'compare'} type
* Kind.
* @property {string} user
* Owner of repo.
*
* @typedef BuildUrlIssueValues
* Arguments for buildUrl functions for issues
* @property {'issue'} type The type of special object
* @property {string} user The owner of the repo
* @property {string} project The project of the repo
* @property {string} no The parsed issue number
* Info for issues.
* @property {string} no
* Issue number.
* @property {string} project
* Project name.
* @property {'issue'} type
* Kind.
* @property {string} user
* Owner of repo.
*
* @typedef BuildUrlMentionValues
* Arguments for buildUrl functions for mentions
* @property {'mention'} type The type of special object
* @property {string} user The parsed user name
* Info for mentions.
* @property {'mention'} type
* Kind.
* @property {string} user
* User name.
*
* @typedef RepositoryInfo
* The owner and project of the repo
* @property {string} user The user/organization name
* @property {string} project The project/repo name
* @typedef {BuildUrlCommitValues | BuildUrlCompareValues | BuildUrlIssueValues | BuildUrlMentionValues} BuildUrlValues
* Info.
*
* @typedef Options
* Configuration.
* @property {string} [repository]
* Repository to link against.
* Detected from the `repository` field in `package.json` if not given.
* Should point to a GitHub repository.
* @property {boolean} [mentionStrong=true]
* Wrap mentions in `strong`.
* This makes them render more like how GitHub styles them.
* But GitHub itself uses CSS instead of strong.
* @property {BuildUrl} [buildUrl]
* Change how (and whether) things are linked.
* @property {BuildUrl | null | undefined} [buildUrl]
* Change how things are linked (optional).
* @property {boolean | null | undefined} [mentionStrong=true]
* Wrap mentions in `strong` (default: `true`);
* this makes them render more like how GitHub styles them, but GH itself
* uses CSS instead of `strong`.
* @property {string | null | undefined} [repository]
* Repository to link against (default: `repository` from `packag.json` in CWD in Node);
* should point to a GitHub repository (such as `'user/project'`)
*
* @typedef RepositoryInfo
* Owner and project of repo.
* @property {string} project
* Project name.
* @property {string} user
* User/organization name.
*
* @typedef UrlInfo
* Info.
* @property {boolean} comment
* Whether the link is to a comment.
* @property {string} page
* Page type.
* @property {string} project
* Project name.
* @property {string} reference
* Reference.
* @property {string} user
* User/organization name.
*/
import {findAndReplace} from 'mdast-util-find-and-replace'
import {toString} from 'mdast-util-to-string'
import {visit} from 'unist-util-visit'
import {toString} from 'mdast-util-to-string'
import {findAndReplace} from 'mdast-util-find-and-replace'
import {getRepoFromPackage} from './get-repo-from-package.js'
import {getRepoFromPackage} from '#get-repo-from-package'
/** @type {Readonly<Options>} */
const emptyOptions = {}
// Previously, GitHub linked `@mention` and `@mentions` to their blog post about

@@ -137,21 +169,82 @@ // mentions (<https://github.com/blog/821>).

/**
* Plugin to autolink references like in GitHub issues, PRs, and comments.
* Create a URL to GH.
*
* @type {import('unified').Plugin<[Options?]|void[], Root>}
* @satisfies {BuildUrl}
* @param {Readonly<BuildUrlValues>} values
* Info on the link to build.
* @returns {string}
* URL to use.
*/
export default function remarkGithub(options = {}) {
return (tree, vfile) => {
const repository = options.repository || getRepoFromPackage(vfile.cwd)
export function defaultBuildUrl(values) {
const base = 'https://github.com'
if (values.type === 'mention') {
return [base, values.user].join('/')
}
const {project, user} = values
if (values.type === 'commit') {
return [base, user, project, 'commit', values.hash].join('/')
}
if (values.type === 'issue') {
return [base, user, project, 'issues', values.no].join('/')
}
// `values.type` is `'compare'`
return [
base,
user,
project,
'compare',
values.base + '...' + values.compare
].join('/')
}
/**
* Link references to users, commits, and issues, in the same way that GitHub
* does in comments, issues, PRs, and releases.
*
* @param {Readonly<Options> | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export default function remarkGithub(options) {
const settings = options || emptyOptions
const buildUrl = settings.buildUrl || defaultBuildUrl
/**
* Transform.
*
* @param {Root} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
// To do: when async/await in React is easier, we can do `getRepoFromPackage` async.
// Then it should throw errors when the repo is incorrect / files are broken / etc.
const repository = settings.repository || getRepoFromPackage(file.cwd)
if (!repository) {
throw new Error('Unexpected missing `repository` in `options`')
}
// Parse the URL: See the tests for all possible kinds.
const repositoryMatch = repoRegex.exec(repository || '')
const repositoryMatch = repoRegex.exec(repository)
if (!repositoryMatch) {
throw new Error('Missing or invalid `repository` field in `options`')
throw new Error(
'Unexpected invalid `repository`, expected for example `user/project`'
)
}
/** @type {RepositoryInfo} */
/** @type {Readonly<RepositoryInfo>} */
const repositoryInfo = {
user: repositoryMatch[1],
project: repositoryMatch[2]
project: repositoryMatch[2],
user: repositoryMatch[1]
}

@@ -171,3 +264,4 @@

visit(tree, 'link', (node) => {
visit(tree, 'link', function (node) {
/** @type {Readonly<UrlInfo> | undefined} */
const link = parse(node)

@@ -195,3 +289,3 @@

/** @type {StaticPhrasingContent[]} */
/** @type {Array<PhrasingContent>} */
const children = []

@@ -221,15 +315,6 @@

/**
* @param {BuildUrlValues} values
* @returns {string|false}
*/
function buildUrl(values) {
if (options.buildUrl) return options.buildUrl(values, defaultBuildUrl)
return defaultBuildUrl(values)
}
/**
* @type {ReplaceFunction}
* @param {string} value
* @param {string} username
* @param {Match} match
* @param {RegExpMatchObject} match
*/

@@ -249,6 +334,6 @@ function replaceMention(value, username, match) {

/** @type {StaticPhrasingContent} */
/** @type {PhrasingContent} */
let node = {type: 'text', value}
if (options.mentionStrong !== false) {
if (settings.mentionStrong !== false) {
node = {type: 'strong', children: [node]}

@@ -264,3 +349,3 @@ }

* @param {string} no
* @param {Match} match
* @param {RegExpMatchObject} match
*/

@@ -275,3 +360,3 @@ function replaceIssue(value, no, match) {

const url = buildUrl({type: 'issue', ...repositoryInfo, no})
const url = buildUrl({no, type: 'issue', ...repositoryInfo})

@@ -288,3 +373,3 @@ return url

* @param {string} b
* @param {Match} match
* @param {RegExpMatchObject} match
*/

@@ -301,6 +386,6 @@ function replaceHashRange(value, a, b, match) {

const url = buildUrl({
base: a,
compare: b,
type: 'compare',
...repositoryInfo,
base: a,
compare: b
...repositoryInfo
})

@@ -321,3 +406,3 @@

* @param {string} value
* @param {Match} match
* @param {RegExpMatchObject} match
*/

@@ -336,3 +421,3 @@ function replaceHash(value, match) {

const url = buildUrl({type: 'commit', ...repositoryInfo, hash: value})
const url = buildUrl({hash: value, type: 'commit', ...repositoryInfo})

@@ -356,3 +441,3 @@ return url

* @param {string} hash
* @param {Match} match
* @param {RegExpMatchObject} match
*/

@@ -369,9 +454,11 @@ // eslint-disable-next-line max-params

const project = specificProject || repositoryInfo.project
const url = no
? buildUrl({type: 'issue', user, project, no})
: buildUrl({type: 'commit', user, project, hash})
/** @type {BuildUrlValues} */
const values = no
? {no, project, type: 'issue', user}
: {hash, project, type: 'commit', user}
const url = buildUrl(values)
if (!url) return false
/** @type {StaticPhrasingContent[]} */
/** @type {Array<PhrasingContent>} */
const nodes = []

@@ -404,3 +491,5 @@ let value = ''

* @param {string} sha
* SHA.
* @returns {string}
* Abbreivated SHA.
*/

@@ -412,38 +501,11 @@ function abbr(sha) {

/**
* Given a set of values based on the values type, returns link URL.
*
* @type {DefaultBuildUrl}
*/
function defaultBuildUrl(values) {
const base = 'https://github.com'
if (values.type === 'mention') return [base, values.user].join('/')
const {project, user} = values
if (values.type === 'commit')
return [base, user, project, 'commit', values.hash].join('/')
if (values.type === 'issue')
return [base, user, project, 'issues', values.no].join('/')
// `values.type` is `'compare'`
return [
base,
user,
project,
'compare',
values.base + '...' + values.compare
].join('/')
}
/**
* Parse a link and determine whether it links to GitHub.
*
* @param {import('mdast').Link} node
* @returns {{user: string, project: string, page: string, reference: string, comment: boolean}|undefined}
* Link node.
* @returns {UrlInfo | undefined}
* Info.
*/
function parse(node) {
const url = node.url || ''
const match = linkRegex.exec(url)
const match = linkRegex.exec(node.url)

@@ -456,3 +518,3 @@ if (

node.children[0].type !== 'text' ||
toString(node) !== url ||
toString(node) !== node.url ||
// SHAs can be min 4, max 40 characters.

@@ -482,9 +544,10 @@ (match[3] === 'commit' && (match[4].length < 4 || match[4].length > 40)) ||

return {
user: match[1],
comment:
node.url.charAt(match[0].length) === '#' &&
match[0].length + 1 < node.url.length,
page: match[3],
project: match[2],
page: match[3],
reference,
comment:
url.charAt(match[0].length) === '#' && match[0].length + 1 < url.length
user: match[1]
}
}
{
"name": "remark-github",
"version": "11.2.4",
"version": "12.0.0",
"description": "remark plugin to autolink references like in GitHub issues, PRs, and comments",
"license": "MIT",
"keywords": [
"unified",
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"writing",
"on",
"github",
"sha",
"user",
"issue",
"markdown",
"mdast",
"mention",
"on",
"plugin",
"pull",
"reference",
"remark",
"remark-plugin",
"request",
"reference"
"sha",
"unified",
"user",
"writing"
],

@@ -38,10 +38,9 @@ "repository": "remarkjs/remark-github",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"browser": {
"./lib/get-repo-from-package.js": "./lib/get-repo-from-package.browser.js"
"exports": "./index.js",
"imports": {
"#get-repo-from-package": {
"node": "./lib/get-repo-from-package.node.js",
"default": "./lib/get-repo-from-package.default.js"
}
},
"react-native": {
"./lib/get-repo-from-package.js": "./lib/get-repo-from-package.browser.js"
},
"files": [

@@ -53,48 +52,41 @@ "lib/",

"dependencies": {
"@types/mdast": "^3.0.0",
"mdast-util-find-and-replace": "^2.0.0",
"mdast-util-to-string": "^3.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"mdast-util-find-and-replace": "^3.0.0",
"mdast-util-to-string": "^4.0.0",
"to-vfile": "^8.0.0",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark": "^14.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark": "^15.0.0",
"remark-cli": "^11.0.0",
"remark-gfm": "^3.0.0",
"remark-gfm": "^4.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"type-fest": "^2.0.0",
"typescript": "^4.0.0",
"vfile": "^5.0.0",
"xo": "^0.50.0"
"type-fest": "^4.0.0",
"typescript": "^5.0.0",
"xo": "^0.56.0"
},
"scripts": {
"build": "rimraf \"{lib,test}/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
"prepack": "npm run build && npm run format",
"test": "npm run build && npm run format && npm run test-coverage",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true,
"rules": {
"unicorn/prefer-node-protocol": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -105,5 +97,8 @@ },

"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}

@@ -11,5 +11,5 @@ # remark-github

[**remark**][remark] plugin to link references to commits, issues, and users,
in the same way that GitHub does in comments, issues, PRs, and releases (see
[Writing on GitHub][writing-on-github]).
**[remark][]** plugin to link references to commits, issues, and users, in the
same way that GitHub does in comments, issues, PRs, and releases (see [Writing
on GitHub][github-writing]).

@@ -23,3 +23,11 @@ ## Contents

* [API](#api)
* [`defaultBuildUrl(values)`](#defaultbuildurlvalues)
* [`unified().use(remarkGithub[, options])`](#unifieduseremarkgithub-options)
* [`BuildUrl`](#buildurl)
* [`BuildUrlCommitValues`](#buildurlcommitvalues)
* [`BuildUrlCompareValues`](#buildurlcomparevalues)
* [`BuildUrlIssueValues`](#buildurlissuevalues)
* [`BuildUrlMentionValues`](#buildurlmentionvalues)
* [`BuildUrlValues`](#buildurlvalues)
* [`Options`](#options)
* [Examples](#examples)

@@ -40,8 +48,2 @@ * [Example: `buildUrl`](#example-buildurl)

**unified** is a project that transforms content with abstract syntax trees
(ASTs).
**remark** adds support for markdown to unified.
**mdast** is the markdown AST that remark uses.
This is a remark plugin that transforms mdast.
## When should I use this?

@@ -72,4 +74,4 @@

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

@@ -83,3 +85,3 @@ ```sh

```js
import remarkGithub from 'https://esm.sh/remark-github@11'
import remarkGithub, {defaultBuildUrl} from 'https://esm.sh/remark-github@12'
```

@@ -91,3 +93,3 @@

<script type="module">
import remarkGithub from 'https://esm.sh/remark-github@11?bundle'
import remarkGithub, {defaultBuildUrl} from 'https://esm.sh/remark-github@12?bundle'
</script>

@@ -98,3 +100,3 @@ ```

Say we have the following file, `example.md`:
Say we have the following file `example.md`:

@@ -122,9 +124,9 @@ ```markdown

And our module, `example.js`, looks as follows:
…and a module `example.js`:
```js
import {read} from 'to-vfile'
import {remark} from 'remark'
import remarkGfm from 'remark-gfm'
import remarkGithub from 'remark-github'
import {read} from 'to-vfile'

@@ -139,3 +141,3 @@ const file = await remark()

Now, running `node example` yields:
…then running `node example.js` yields:

@@ -145,18 +147,18 @@ ```markdown

* Commit: [`f808317`](https://github.com/remarkjs/remark-github/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (fork): [foo@`f808317`](https://github.com/foo/remark-github/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (repo): [remarkjs/remark@`e1aa9f6`](https://github.com/remarkjs/remark/commit/e1aa9f6c02de18b9459b7d269712bcb50183ce89)
* Issue or PR (`#`): [#1](https://github.com/remarkjs/remark-github/issues/1)
* Issue or PR (`GH-`): [GH-1](https://github.com/remarkjs/remark-github/issues/1)
* Issue or PR (fork): [foo#1](https://github.com/foo/remark-github/issues/1)
* Issue or PR (project): [remarkjs/remark#1](https://github.com/remarkjs/remark/issues/1)
* Mention: [**@wooorm**](https://github.com/wooorm)
* Commit: [`f808317`](https://github.com/remarkjs/remark-github/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (fork): [foo@`f808317`](https://github.com/foo/remark-github/commit/f8083175fe890cbf14f41d0a06e7aa35d4989587)
* Commit (repo): [remarkjs/remark@`e1aa9f6`](https://github.com/remarkjs/remark/commit/e1aa9f6c02de18b9459b7d269712bcb50183ce89)
* Issue or PR (`#`): [#1](https://github.com/remarkjs/remark-github/issues/1)
* Issue or PR (`GH-`): [GH-1](https://github.com/remarkjs/remark-github/issues/1)
* Issue or PR (fork): [foo#1](https://github.com/foo/remark-github/issues/1)
* Issue or PR (project): [remarkjs/remark#1](https://github.com/remarkjs/remark/issues/1)
* Mention: [**@wooorm**](https://github.com/wooorm)
Some links:
* Commit: [remarkjs/remark@`e1aa9f6`](https://github.com/remarkjs/remark/commit/e1aa9f6c02de18b9459b7d269712bcb50183ce89)
* Commit comment: [remarkjs/remark@`ac63bc3` (comment)](https://github.com/remarkjs/remark/commit/ac63bc3abacf14cf08ca5e2d8f1f8e88a7b9015c#commitcomment-16372693)
* Issue or PR: [remarkjs/remark#182](https://github.com/remarkjs/remark/issues/182)
* Issue or PR comment: [#3 (comment)](https://github.com/remarkjs/remark-github/issues/3#issue-151160339)
* Mention: <https://github.com/ben-eb>
* Commit: [remarkjs/remark@`e1aa9f6`](https://github.com/remarkjs/remark/commit/e1aa9f6c02de18b9459b7d269712bcb50183ce89)
* Commit comment: [remarkjs/remark@`ac63bc3` (comment)](https://github.com/remarkjs/remark/commit/ac63bc3abacf14cf08ca5e2d8f1f8e88a7b9015c#commitcomment-16372693)
* Issue or PR: [remarkjs/remark#182](https://github.com/remarkjs/remark/issues/182)
* Issue or PR comment: [#3 (comment)](https://github.com/remarkjs/remark-github/issues/3#issue-151160339)
* Mention: <https://github.com/ben-eb>
```

@@ -166,48 +168,135 @@

This package exports no identifiers.
The default export is `remarkGithub`.
This package exports the identifier [`defaultBuildUrl`][api-default-build-url].
The default export is [`remarkGithub`][api-remark-github].
### `defaultBuildUrl(values)`
Create a URL to GH.
###### Parameters
* `values` ([`BuildUrlValues`][api-build-url-values])
— info on the link to build
###### Returns
URL to use (`string`).
### `unified().use(remarkGithub[, options])`
Link references to users, commits, and issues, in the same way that GitHub does
in comments, issues, PRs, and releases (see
[Writing on GitHub][writing-on-github]).
in comments, issues, PRs, and releases.
##### `options`
###### Parameters
Configuration (optional).
* `options` ([`Options`][api-options], optional)
— configuration
###### `options.repository`
###### Returns
Repository to link against (`string`, optional).
Detected in Node.js from the `repository` field in `package.json` if not given.
Should point to a GitHub repository, such as
`'https://github.com/user/project.git'` or `'user/project'`.
Transform ([`Transformer`][unified-transformer]).
###### `options.mentionStrong`
### `BuildUrl`
Wrap mentions in `strong` (`boolean`, default: `true`).
This makes them render more like how GitHub styles them.
But GitHub itself uses CSS instead of strong.
Create a URL (TypeScript type).
###### `options.buildUrl`
###### Parameters
Change how (and whether) things are linked (`Function`, optional).
This can be used to point links to GitHub Enterprise or other places.
It’s called with the following parameters:
* `values` (`BuildUrlValues`)
* `values` ([`BuildUrlValues`][api-build-url-values])
— info on the link to build
* `defaultBuildUrl` (`(values: BuildUrlValues) => string`)
— function that can be called to perform normal behavior
It should return the URL to use (`string`) or `false` to not create a link.
###### Returns
The following schemas are passed as `BuildUrlValues`:
URL to use or `false` to not link (`string | false`).
* `{type: 'commit', user, project, hash}`
* `{type: 'compare', user, project, base, compare}`
* `{type: 'issue', user, project, no}`
* `{type: 'mention', user}`
### `BuildUrlCommitValues`
Info for commit hash (TypeScript type).
###### Fields
* `hash` (`string`)
— commit hash value
* `project` (`string`)
— project name
* `type` (`'commit'`)
— kind
* `user` (`string`)
— owner of repo
### `BuildUrlCompareValues`
Info for commit hash ranges (TypeScript type).
###### Fields
* `base` (`string`)
— SHA of the range start
* `compare` (`string`)
— SHA of the range end
* `project` (`string`)
— project name
* `type` (`'compare'`)
— kind
* `user` (`string`)
— owner of repo
### `BuildUrlIssueValues`
Info for issues (TypeScript type).
###### Fields
* `no` (`string`)
— issue number
* `project` (`string`)
— project name
* `type` (`'issue'`)
— kind
* `user` (`string`)
— owner of repo
### `BuildUrlMentionValues`
Info for mentions (TypeScript type).
###### Fields
* `type` (`'mention'`)
— kind
* `user` (`string`)
— user name
### `BuildUrlValues`
Info (TypeScript type).
###### Type
```ts
type BuildUrlValues =
| BuildUrlCommitValues
| BuildUrlCompareValues
| BuildUrlIssueValues
| BuildUrlMentionValues
```
### `Options`
Configuration (TypeScript type).
###### Fields
* `buildUrl` ([`BuildUrl`][api-build-url], default:
[`defaultBuildUrl`][api-default-build-url])
— change how things are linked
* `mentionStrong` (`boolean`, default: `true`)
— wrap mentions in `strong`;
this makes them render more like how GitHub styles them, but GH itself
uses CSS instead of `strong`
* `repository` (`string`, default: `repository` from `packag.json` in CWD in
Node, otherwise required)
— repository to link against;
should point to a GitHub repository (such as `'user/project'`)
## Examples

@@ -221,15 +310,20 @@

```diff
@@ -8,7 +8,11 @@ main()
async function main() {
const file = await remark()
.use(remarkGfm)
- .use(remarkGithub)
+ .use(remarkGithub, {
+ buildUrl(values, defaultBuildUrl) {
+ return values.type === 'mention' ? false : defaultBuildUrl(values)
+ }
+ })
.process(await read('example.md'))
@@ -1,11 +1,15 @@
import {remark} from 'remark'
import remarkGfm from 'remark-gfm'
-import remarkGithub from 'remark-github'
+import remarkGithub, {defaultBuildUrl} from 'remark-github'
import {read} from 'to-vfile'
console.log(String(file))
const file = await remark()
.use(remarkGfm)
- .use(remarkGithub)
+ .use(remarkGithub, {
+ buildUrl(values) {
+ return values.type === 'mention' ? false : defaultBuildUrl(values)
+ }
+ })
.process(await read('example.md'))
console.log(String(file))
```

@@ -240,17 +334,22 @@

```diff
@@ -8,7 +8,13 @@ main()
async function main() {
const file = await remark()
.use(remarkGfm)
- .use(remarkGithub)
+ .use(remarkGithub, {
+ buildUrl(values, defaultBuildUrl) {
+ return values.type === 'mention'
+ ? `https://yourwebsite.com/${values.user}/`
+ : defaultBuildUrl(values)
+ }
+ })
.process(await read('example.md'))
@@ -1,11 +1,17 @@
import {remark} from 'remark'
import remarkGfm from 'remark-gfm'
-import remarkGithub from 'remark-github'
+import remarkGithub, {defaultBuildUrl} from 'remark-github'
import {read} from 'to-vfile'
console.log(String(file))
const file = await remark()
.use(remarkGfm)
- .use(remarkGithub)
+ .use(remarkGithub, {
+ buildUrl(values) {
+ return values.type === 'mention'
+ ? `https://yourwebsite.com/${values.user}/`
+ : defaultBuildUrl(values)
+ }
+ })
.process(await read('example.md'))
console.log(String(file))
```

@@ -263,26 +362,34 @@

* Commits:
`1f2a4fb` → [`1f2a4fb`][sha]
`1f2a4fb` →
[`1f2a4fb`][github-sha]
* Commits across forks:
`remarkjs@1f2a4fb` → [remarkjs@`1f2a4fb`][sha]
`remarkjs@1f2a4fb` →
[remarkjs@`1f2a4fb`][github-sha]
* Commits across projects:
`remarkjs/remark-github@1f2a4fb` → [remarkjs/remark-github@`1f2a4fb`][sha]
`remarkjs/remark-github@1f2a4fb` →
[remarkjs/remark-github@`1f2a4fb`][github-sha]
* Compare ranges:
`e2acebc...2aa9311` →
[`e2acebc...2aa9311`][sha-range]
[`e2acebc...2aa9311`][github-sha-range]
* Compare ranges across forks:
`remarkjs@e2acebc...2aa9311` →
[remarkjs/remark-github@`e2acebc...2aa9311`][sha-range]
[remarkjs/remark-github@`e2acebc...2aa9311`][github-sha-range]
* Compare ranges across projects:
`remarkjs/remark-github@e2acebc...2aa9311` →
[remarkjs/remark-github@`e2acebc...2aa9311`][sha-range]
[remarkjs/remark-github@`e2acebc...2aa9311`][github-sha-range]
* Prefix issues:
`GH-1` → [GH-1][issue]
`GH-1` →
[GH-1][github-issue]
* Hash issues:
`#1` → [#1][issue]
`#1` →
[#1][github-issue]
* Issues across forks:
`remarkjs#1` → [remarkjs#1][issue]
`remarkjs#1` →
[remarkjs#1][github-issue]
* Issues across projects:
`remarkjs/remark-github#1` → [remarkjs/remark-github#1][issue]
`remarkjs/remark-github#1` →
[remarkjs/remark-github#1][github-issue]
* At-mentions:
`@wooorm` → [**@wooorm**][mention]
`@wooorm` →
[**@wooorm**][github-mention]

@@ -295,15 +402,22 @@ Autolinks to these references are also transformed:

This package is fully typed with [TypeScript][].
It exports an `Options` type, which specifies the interface of the accepted
options.
There are also `BuildUrl`, `BuildUrlValues`, `BuildUrlCommitValues`,
`BuildUrlCompareValues`, `BuildUrlIssueValues`, `BuildUrlMentionValues`,
and `DefaultBuildUrl` types exported.
It exports the additional types
[`BuildUrl`][api-build-url],
[`BuildUrlCommitValues`][api-build-url-commit-values],
[`BuildUrlCompareValues`][api-build-url-compare-values],
[`BuildUrlIssueValues`][api-build-url-issue-values],
[`BuildUrlMentionValues`][api-build-url-mention-values],
[`BuildUrlValues`][api-build-url-values],
[`DefaultBuildUrl`][api-default-build-url],
[`Options`][api-options].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `remark-github@^12`,
compatible with Node.js 16.
This plugin works with `unified` version 6+ and `remark` version 7+.

@@ -313,5 +427,5 @@

Use of `remark-github` does not involve [**rehype**][rehype] ([**hast**][hast]).
Use of `remark-github` does not involve **[rehype][]** (**[hast][]**).
It does inject links based on user content, but those links only go to GitHub.
There are no openings for [cross-site scripting (XSS)][xss] attacks.
There are no openings for [cross-site scripting (XSS)][wiki-xss] attacks.

@@ -356,5 +470,5 @@ ## Related

[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-github.svg
[size-badge]: https://img.shields.io/bundlejs/size/remark-github
[size]: https://bundlephobia.com/result?p=remark-github
[size]: https://bundlejs.com/?q=remark-github

@@ -373,2 +487,4 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh

@@ -378,7 +494,7 @@

[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md

@@ -389,28 +505,48 @@ [license]: license

[github-issue]: https://github.com/remarkjs/remark-github/issues/1
[github-mention]: https://github.com/wooorm
[github-sha]: https://github.com/remarkjs/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921
[github-sha-range]: https://github.com/wooorm/remark/compare/e2acebc...2aa9311
[github-writing]: https://docs.github.com/en/github/writing-on-github#references
[hast]: https://github.com/syntax-tree/hast
[rehype]: https://github.com/rehypejs/rehype
[remark]: https://github.com/remarkjs/remark
[remark-gfm]: https://github.com/remarkjs/remark-gfm
[remark-breaks]: https://github.com/remarkjs/remark-breaks
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
[typescript]: https://www.typescriptlang.org
[unified]: https://github.com/unifiedjs/unified
[writing-on-github]: https://docs.github.com/en/github/writing-on-github#references
[unified-transformer]: https://github.com/unifiedjs/unified#transformer
[sha]: https://github.com/remarkjs/remark-github/commit/1f2a4fb8f88a0a98ea9d0c0522cd538a9898f921
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[sha-range]: https://github.com/wooorm/remark/compare/e2acebc...2aa9311
[api-options]: #options
[issue]: https://github.com/remarkjs/remark-github/issues/1
[api-remark-github]: #unifieduseremarkgithub-options
[mention]: https://github.com/wooorm
[api-build-url]: #buildurl
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[api-build-url-commit-values]: #buildurlcommitvalues
[typescript]: https://www.typescriptlang.org
[api-build-url-compare-values]: #buildurlcomparevalues
[rehype]: https://github.com/rehypejs/rehype
[api-build-url-issue-values]: #buildurlissuevalues
[hast]: https://github.com/syntax-tree/hast
[api-build-url-mention-values]: #buildurlmentionvalues
[remark-gfm]: https://github.com/remarkjs/remark-gfm
[api-build-url-values]: #buildurlvalues
[remark-breaks]: https://github.com/remarkjs/remark-breaks
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
[api-default-build-url]: #
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