linkifyjs
linkifyjs copied to clipboard
100% control of returned value
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
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
Now possible generally in v4 with the render
option.