Last active
September 6, 2015 20:24
-
-
Save andrewagain/e26501994567f5ad5ada to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react' | |
import Emoji from 'emojione' | |
var Emojify = React.createClass({ | |
convert(line) { | |
let data = line.match(/\<img class\=\"([^"]*)\" alt\=\"([^"]*)\" src\=\"([^"]*)\"\/\>/i) | |
//return data[2] | |
return ( | |
<img class={data[0]} alt={data[1]} src={data[2]}/> | |
) | |
}, | |
makeRealImages(html) { | |
var matches = html.match(/\<img class\=\"([^"]*)\" alt\=\"([^"]*)\" src\=\"([^"]*)\"\/\>/gi) | |
if (matches) { | |
return matches.map((item, key) => { | |
return this.convert(item) | |
}) | |
} | |
return null; | |
}, | |
render() { | |
let { children } = this.props | |
children = this.makeRealImages(Emoji.toImage(children)) | |
return ( | |
<span>{children}</span> | |
) | |
} | |
}) | |
export default Emojify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment