4.1.0 • Published 10 months ago

linkify-issues v4.1.0

Weekly downloads
626
License
MIT
Repository
github
Last release
10 months ago

linkify-issues

Linkify GitHub issue references

Install

npm install linkify-issues

Usage

import {linkifyUrlsToHtml} from 'linkify-issues';

linkifyUrlsToHtml('Fixes #143 and avajs/ava#1023', {
	user: 'sindresorhus',
	repository: 'dofle',
	attributes: {
		class: 'unicorn',
		multiple: ['a', 'b'],
		number: 1,
		exclude: false,
		include: true
	}
});
//=> 'Fixes <a href="https://github.com/sindresorhus/dofle/issues/143" class="unicorn" multiple="a b" number="1" include>#143</a> and <a href="https://github.com/avajs/ava/issues/1023" class="unicorn" multiple="a b" number="1" include>avajs/ava#1023</a>'
import {linkifyUrlsToDom} from 'linkify-issues';

const fragment = linkifyUrlsToDom('See #143', {
	user: 'sindresorhus',
	repository: 'dofle',
	attributes: {
		class: 'unicorn',
	}
});

document.body.appendChild(fragment);

API

linkifyUrlsToHtml(string, options)

Returns an HTML string like 'See <a href="https://github.com/sindresorhus/dofle/issue/143">#143</a>'.

string

Type: string

A string with issue references to linkify.

options

Type: object

user

Required\ Type: string

GitHub user.

repository

Required\ Type: string

GitHub repository.

attributes

Type: object

HTML attributes to add to the link.

baseUrl

Type: string\ Default: 'https://github.com'

The base URL.

additionalPrefix

Type: string | undefined\ Default: 'GH-'

Additional reference prefix to support. It can be set to undefined to disable the default.

linkifyUrlsToHtml('Will not linkify GH-123', {
	additionalPrefix: undefined
});
// => 'Will not linkify GH-123'
linkifyUrlsToHtml('Will link SOUP:235 but not GH-123', {
	additionalPrefix: 'SOUP:'
});
// => 'Will link <a href="https://github.com/sindresorhus/dofle/issues/235">SOUP-235</a> but not GH-123'

!NOTE additionalPrefix is added unescaped to the regex, keep it simple.

linkifyUrlsToDom(string, options)

Returns a DocumentFragment ready to be appended in a DOM safely, like DocumentFragment(TextNode('See '), HTMLAnchorElement('#143')).

This only works in the browser.

options

See options above.

Related