Download spectrum/api/utils/markdown-linkify.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 835 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/utils/markdown-linkify.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/utils/markdown-linkify.js
-
curl -L -o markdown-linkify.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/utils/markdown-linkify.js
835 Bytes
| const Linkify = require('linkify-it'); | |
| const linkifier = new Linkify(undefined, { | |
| fuzzyEmail: false, | |
| }); | |
| /** | |
| * Replace URLs in text with markdown links | |
| * (this is used in a migration script so it has to be Node-compat ES6 only) | |
| */ | |
| const linkify = (text /*: string*/ /*: string*/) => { | |
| const matches = linkifier.match(text); | |
| if (!matches) return text; | |
| let out = text; | |
| let last = 0; | |
| const result = []; | |
| if (matches) { | |
| matches.forEach(function(match) { | |
| if (last < match.index) { | |
| result.push(text.slice(last, match.index)); | |
| } | |
| result.push(`[${match.text}](${match.url})`); | |
| last = match.lastIndex; | |
| }); | |
| if (last < text.length) { | |
| result.push(text.slice(last)); | |
| } | |
| out = result.join(''); | |
| } | |
| return out; | |
| }; | |
| module.exports = linkify; | |