Download react-spring/docs/scripts/mdx/rehype-meta-attribute.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/scripts/mdx/rehype-meta-attribute.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/scripts/mdx/rehype-meta-attribute.js
-
curl -L -o rehype-meta-attribute.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/scripts/mdx/rehype-meta-attribute.js
664 Bytes
| /** | |
| * Credit to https://ped.ro/writing/code-blocks-but-better | |
| */ | |
| import { visit } from 'unist-util-visit' | |
| const re = /\b([-\w]+)(?:=(?:"([^"]*)"|'([^']*)'|([^"'\s]+)))?/g | |
| export default (options = {}) => { | |
| return tree => { | |
| visit(tree, 'element', visitor) | |
| } | |
| function visitor(node, index, parentNode) { | |
| let match | |
| if (node.tagName === 'code' && node.data && node.data.meta) { | |
| re.lastIndex = 0 // Reset regex. | |
| while ((match = re.exec(node.data.meta))) { | |
| node.properties[match[1]] = match[2] || match[3] || match[4] || '' | |
| parentNode.properties[match[1]] = match[2] || match[3] || match[4] || '' | |
| } | |
| } | |
| } | |
| } | |