
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
react-linkify-all
Advanced tools
Modal pop up on hover, clickable links in text - everything is here. This is NPM package that converts text with links into an array of React components. Customizable. Built-in support of emails, Telegram, Twitter mentions. Own pattern can be used to link
Try it on CodeSandBox: https://codesandbox.io/s/compassionate-meitner-y8d9l9
Popup functionality:
Code:
Modal pop up on hover, clickable links in text - everything is here. This is NPM package that converts text with links into an array of React components. Customizable. Built-in support of emails, Telegram, Twitter mentions. Modal pop up can be implemented as it shown above. Own pattern can be used to linkify everything
npm i react-linkify-all
import { Linkify } from 'react-linkify-all'
...
<Linkify links twitters emails>Some text with links.net, @twitters and emails@domain.org</Linkify>
Available props: emails, instagrams, links, tgs, twitters
And their corresponding components: <Emails/>, <Instagrams/>, <Links/>, <Tgs/>, <Twitters/>
Also you can use method linkify()
to linkify(an example is given below).
Code:
Result HTML:
Nesting is not supported yet: use <Linkify links twitters emails... />
to summarize effects
You could use your own component for links:
const component = (match, i, link) => {
return <a href={link} style={{color:"yellow"}}>#{i}. {match}</a>;
}
...
<Linkify ... component={component}>...</Linkify>
The "i" parameter can be used to number links(there is a counter for each type of link) Parameters "match" and "link" may differ.
Example #1:
<Links>site.com</Links>
match: site.com
link: https://site.com
i: 1
Every pattern for linkify is set by an object:
const option = {
regex: RegExp, // /(...)/g,
component?: (match, i, link) => ReactElement,
linkFn?: (match:string) => string
}
WARNING: be sure to put parentheses around the regular expression. In addition, every internal capturing group should be not captured. RegEx should capture only the entrie word you need.
The default component is:
const defaultComponent = (match, i, link) => <a href={link}>{match}</a>;
"linkFn" is a function for converting a match into a link. In Example #1 above, linkFn is:
const example = match => match.substring(0, 4) === 'http' ? match : 'https://'+match
(It is used to handle matches like site.com and https://site.com)
const option = {
regex: new RegExp("((?<=\\B)@[a-zA-Z0-9_]{5,32}(?=\\b))", "g"),
component: (match, i, link) => <a href={link}>{match}</a>,
linkFn: match => "https://twitter.com/"+match.substring(1)
};
...
<Linkify options={option}>...</Linkify>
This example will wrap every Twitter profile mention into <a/> tag.
Also, you can combine options:
<Linkify options={[option1, option2, ..., optionN]}>...</Linkify>
They will be applied consistently
import { linkify } from 'react-linkify-all';
...
const Card = (text) => {
const option = ...;
const result = linkify(text, option);
return <div>{result}</div>;
}
If you find react-linkify-all to be useful in your project, please consider to star and support it: https://github.com/suvmer/react-linkify-all
If you want to contact me, send an email to suvmers@gmail.com
I'm also available on Telegram: https://t.me/suvmers
FAQs
Modal pop up on hover, clickable links in text - everything is here. This is NPM package that converts text with links into an array of React components. Customizable. Built-in support of emails, Telegram, Twitter mentions. Own pattern can be used to link
The npm package react-linkify-all receives a total of 0 weekly downloads. As such, react-linkify-all popularity was classified as not popular.
We found that react-linkify-all demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.