Skip to content

Instantly share code, notes, and snippets.

@remiq
Created October 31, 2015 15:42
Show Gist options
  • Save remiq/608c4b29773a4f7b7cd3 to your computer and use it in GitHub Desktop.
Save remiq/608c4b29773a4f7b7cd3 to your computer and use it in GitHub Desktop.
React's Message class for parsing links
class Message extends React.Component {
parseLinks(body) {
body = body.split(/(http[^ ]+)/)
body = body.map(function(url) {
if (url.match(/(http[^ ]+)/)) {
var href = "/r?url=" + encodeURIComponent(url)
var key = Math.random()
return <a key={key} href={href} target="_blank">{url}</a>
} else {
return url
}
})
return body
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment