import React from 'react'; import PropTypes from 'prop-types'; import {FormattedMessage} from 'react-intl'; import styles from './description.css'; import reactStringReplace from 'react-string-replace'; const decorate = text => { // https://github.com/LLK/scratch-www/blob/25232a06bcceeaddec8fcb24fb63a44d870cf1cf/src/lib/decorate-text.jsx // Make @mentions clickable text = reactStringReplace(text, /@([\w-]+)/, (match, i) => ( {`@${match}`} )); // Make links clickable const linkRegex = /(https?:\/\/[\w\d_\-.]{1,256}(?:\/(?:\S*[\w:/#[\]@$&'()*+=])?)?(?![^?!,:;\w\s]\S))/g; text = reactStringReplace(text, linkRegex, (match, i) => ( {match} )); // Make hashtags clickable text = reactStringReplace(text, /#([\w-]+)/g, (match, i) => ( {`#${match}`} )); return text; }; const Description = ({ instructions, credits, projectId }) => instructions !== 'unshared' && credits !== 'unshared' && (
{instructions ? (

{decorate(instructions)}
) : null} {instructions && credits ? (
) : null} {credits && (

{decorate(credits)}
)}
); Description.propTypes = { instructions: PropTypes.string, credits: PropTypes.string, projectId: PropTypes.string }; export default Description;