diff --git a/src/components/pages/News.js b/src/components/pages/News.js index a550e8de4f217883058c307e244f4bcf1cfae2a8..31b6c13bdb76c60e76b5a31d9585ffe4ec1471b2 100644 --- a/src/components/pages/News.js +++ b/src/components/pages/News.js @@ -10,6 +10,19 @@ import EditNewsForm from '../forms/EditNewsForm'; import { connect } from 'react-redux'; import moment from 'moment'; +const linkify = (text) => { + const urlRegex = /(https?:\/\/[^\s]+)/g; + return text.split(urlRegex).map((part, index) => + part.match(urlRegex) ? ( + <a key={index} href={part} target="_blank" rel="noopener noreferrer"> + {part} + </a> + ) : ( + part + ) + ); +}; + class News extends Component { UNSAFE_componentWillMount() { this.props.getNews(); @@ -61,7 +74,7 @@ class News extends Component { renderMultiLine = (text) => { const strings = text.split('\n'); - return strings.map((string) => <p key={Math.random()}>{string}</p>); + return strings.map((string) => <p key={Math.random()}>{linkify(string)}</p>); }; render() {