Download spectrum/src/helpers/render-text-with-markdown-links.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 626 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/helpers/render-text-with-markdown-links.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/src/helpers/render-text-with-markdown-links.js
-
curl -L -o render-text-with-markdown-links.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/helpers/render-text-with-markdown-links.js
626 Bytes
| // @flow | |
| import * as React from 'react'; | |
| import replace from 'string-replace-to-array'; | |
| import { Link } from 'react-router-dom'; | |
| import { SPECTRUM_URLS } from 'shared/regexps'; | |
| const MARKDOWN_LINK = /(?:\[(.*?)\]\((.*?)\))/g; | |
| export default (text: string) => { | |
| return replace(text, MARKDOWN_LINK, (fullLink, text, url) => { | |
| const regexp = new RegExp(SPECTRUM_URLS, 'ig'); | |
| const match = regexp.exec(url); | |
| if (match && match[0] && match[1]) return <Link to={match[1]}>{text}</Link>; | |
| return ( | |
| <a href={url} target="_blank" rel="noopener noreferrer" key={url}> | |
| {text} | |
| </a> | |
| ); | |
| }); | |
| }; | |