Add a tag to links

This commit is contained in:
Berkeley Martinez
2015-10-30 16:58:49 -07:00
parent 9637c8739a
commit 6aa19ef247
2 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { Well, Row, Col, Thumbnail, Panel } from 'react-bootstrap'; import { Well, Row, Col, Thumbnail, Panel } from 'react-bootstrap';
import urlRegexFactory from 'url-regex';
const urlRegex = urlRegexFactory();
const defaultImage = const defaultImage =
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png'; 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
@ -10,6 +12,12 @@ const thumbnailStyle = {
maxWidth: '100px' maxWidth: '100px'
}; };
function addATags(text) {
return text.replace(urlRegex, function(match) {
return `<a href=${match}>${match}</a>`;
});
}
export default React.createClass({ export default React.createClass({
displayName: 'ShowJob', displayName: 'ShowJob',
propTypes: { propTypes: {
@ -90,10 +98,12 @@ export default React.createClass({
<Col <Col
md={ 6 } md={ 6 }
mdOffset={ 3 }> mdOffset={ 3 }>
<bold>How do I apply? </bold> <bold>How do I apply?</bold>
<br /> <br />
<br /> <br />
{ howToApply } <span dangerouslySetInnerHTML={{
__html: addATags(howToApply)
}} />
</Col> </Col>
</Row> </Row>
</Well> </Well>

View File

@ -113,6 +113,7 @@
"thundercats-react": "^0.3.0", "thundercats-react": "^0.3.0",
"twit": "~1.1.20", "twit": "~1.1.20",
"uglify-js": "~2.4.15", "uglify-js": "~2.4.15",
"url-regex": "^3.0.0",
"validator": "^3.22.1", "validator": "^3.22.1",
"webpack": "^1.9.12", "webpack": "^1.9.12",
"xss-filters": "^1.2.6", "xss-filters": "^1.2.6",