linkifyjs icon indicating copy to clipboard operation
linkifyjs copied to clipboard

100% control of returned value

Open mmunchandersen opened this issue 5 years ago • 1 comments

Hi.

Recently, I had to detect if links in a text were of type "video links" (i.e., https://youtube.com/[video-id]) and return a string where the video link in the text was transformed into an embedded video.

Example

Function input: "Cras ut feugiat arcu. https://youtube.com/[video-id] Etiam mattis eu purus eu feugiat"

Function output: "Cras ut feugiat arcu. Etiam mattis eu purus eu feugiat"

A method that would allow 100% control of the returned link string would be a great addition to this great library.

Thanks

mmunchandersen avatar Sep 03 '19 06:09 mmunchandersen

Hi @mmunchandersen, there's no easy way to do this consistently with all of Linkify's interfaces (i.e., linkify-string, linkify-react, etc.) yet.

The only potential solution I can recommend is using the linkify.tokenize function

This accepts a string and returns an array of objects to represents each type of entity Linkify handles (URLs, emails, plain text, etc). You can conceivably use this for full control of the output - see the Linkify-string implementation for example use:

https://github.com/Hypercontext/linkifyjs/blob/ea83f5affa1dd5cf120560bb07bebcc5a3cec98a/src/linkify-string.js#L32-L77

nfrasser avatar Jan 31 '20 00:01 nfrasser

Now possible generally in v4 with the render option.

nfrasser avatar Sep 19 '22 01:09 nfrasser