sindresorhus / linkify-urls

Linkify URLs in a string
MIT License
160 stars 22 forks source link

Allow custom HTML value #10

Closed rooneyg21 closed 5 years ago

rooneyg21 commented 6 years ago

This would help solve sindresorhus/refined-github#703

const linkify = (href, options) => createHtmlElement({
    name: 'a',
    attributes: Object.assign({href: ''}, options.attributes, {href}),
    value: options.value || href
}); 

If the user can pass the value as part of the options, the library can parse the href text and add an anchor element that has whatever the user wants as its text (HTML in the case of sindresorhus/refined-github#695 to preserve the span tags)

sindresorhus commented 6 years ago

Sure. Pull request welcome.

fregante commented 6 years ago

Sadly this isn't useful if linkify-urls is used to to match URLs inside random strings.

https://runkit.com/embed/rys5wsu5zn99

If we don't know what part of input is a URL, when does a static value ever come useful? It should be a callback on each matched URL.

Related: https://github.com/sindresorhus/refined-github/issues/811#issuecomment-350296939

sindresorhus commented 5 years ago

Fixed by #18