Use a fork of autolinker with react support to get rid off dangerouslySetInnerHTML
This commit is contained in:
parent
072daa64f2
commit
47ebd9c84c
6 changed files with 44 additions and 27 deletions
17
client/src/js/util/linkify.js
Normal file
17
client/src/js/util/linkify.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import Autolinker from 'autolinker';
|
||||
import React from 'react';
|
||||
|
||||
const autolinker = new Autolinker({
|
||||
stripPrefix: false,
|
||||
doJoin: false,
|
||||
replaceFn: (linker, match) => {
|
||||
if (match.getType() === 'url') {
|
||||
return <a target="_blank" href={match.getAnchorHref()}>{match.getAnchorText()}</a>;
|
||||
}
|
||||
},
|
||||
React
|
||||
});
|
||||
|
||||
export default function linkify(text) {
|
||||
return autolinker.link(text);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue