Linkify GitHub issue references
npm install linkify-issues
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);
Returns an HTML string like 'See <a href="https://github.com/sindresorhus/dofle/issue/143">#143</a>'
.
Type: string
A string with issue references to linkify.
Type: object
Required
Type: string
GitHub user.
Required
Type: string
GitHub repository.
Type: object
HTML attributes to add to the link.
Type: string
Default: 'https://github.com'
The base URL.
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
The prefix is added unescaped to the regex, keep it simple.
Returns a DocumentFragment
ready to be appended in a DOM safely, like DocumentFragment(TextNode('See '), HTMLAnchorElement('#143'))
.
This only works in the browser.
See options above.
- issue-regex - Regular expression for matching issue references
- linkify-urls - Linkify URLs in text