{"_id":"@dword-design/rehype-urls","name":"@dword-design/rehype-urls","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@dword-design/rehype-urls","version":"0.0.1","description":"Rehype plugin to rewrite URLs of `href` and `src` attributes","main":"index.js","scripts":{"test":"tape test.js && standard"},"repository":{"type":"git","url":"git+https://github.com/brechtcs/rehype-urls.git"},"keywords":["rehype","hast","rewrite","url","link","src","href"],"bugs":{"url":"https://github.com/brechtcs/rehype-urls/issues"},"homepage":"https://github.com/brechtcs/rehype-urls#readme","author":{"name":"Brecht Savelkoul","email":"brecht.savelkoul@gmail.com"},"license":"Apache-2.0","dependencies":{"hast-util-has-property":"^1.0.2","stdopt":"^2.0.0","unist-util-visit":"^1.4.0"},"devDependencies":{"rehype":"^7.0.0","standard":"^12.0.1","tape":"^4.9.1"},"gitHead":"c1a1e1ba2364c873293a2bb69516d51bcce77d50","_id":"@dword-design/rehype-urls@0.0.1","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-ZPtr44motyKRwNWbVSH8DAV6kPIEPziipHCNt3GpYwRWIXeVj+vYShTLbevwPdXyQ3FQ7S0CckRnZ6V/nzn0tg==","shasum":"debb6eaa014fe6151433798fe7c62fe55d93664c","tarball":"https://registry.npmjs.org/@dword-design/rehype-urls/-/rehype-urls-0.0.1.tgz","fileCount":7,"unpackedSize":16187,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIELl0jzuDSlS9ytlEqV+bmNd6bgg0lsnZ7EsxWD+QPfOAiAAqaW1OZzHykS/vSxlGevCgJuikwIxr2JQYz+gKWzyzg=="}]},"_npmUser":{"name":"dword-design","email":"info@sebastianlandwehr.com"},"directories":{},"maintainers":[{"name":"dword-design","email":"info@sebastianlandwehr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rehype-urls_0.0.1_1686345690801_0.3362037912476936"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-09T21:21:30.739Z","0.0.1":"2023-06-09T21:21:31.001Z","modified":"2023-06-09T21:21:31.173Z"},"maintainers":[{"name":"dword-design","email":"info@sebastianlandwehr.com"}],"description":"Rehype plugin to rewrite URLs of `href` and `src` attributes","homepage":"https://github.com/brechtcs/rehype-urls#readme","keywords":["rehype","hast","rewrite","url","link","src","href"],"repository":{"type":"git","url":"git+https://github.com/brechtcs/rehype-urls.git"},"author":{"name":"Brecht Savelkoul","email":"brecht.savelkoul@gmail.com"},"bugs":{"url":"https://github.com/brechtcs/rehype-urls/issues"},"license":"Apache-2.0","readme":"# rehype-urls\n\nRehype plugin to rewrite URLs of `href` and `src` attributes.\n\n## Installation\n\n```sh\nnpm install rehype-urls\n```\n\n## Usage\n\nGiven this markup:\n\n```html\n<article>\n  <img src=\"http://internal.site/image.jpg\">\n  <a href=\"http://internal.site/page.html\">page</a>\n  <a href=\"http://example.com\">link</a>\n</article>\n```\n\nYou can use the following script:\n\n```js\nvar rehype = require('rehype')\nvar urls = require('rehype-urls')\n\nrehype()\n  .use(urls, removeBaseUrl)\n  .process(input, handleOutput)\n\nfunction removeBaseUrl (url) {\n  if (url.host === 'internal.site') {\n    return url.path\n  }\n}\n```\n\nWhich will transform it into:\n\n```html\n<article>\n  <img src=\"/image.jpg\">\n  <a href=\"/page.html\">page</a>\n  <a href=\"http://example.com\">link</a>\n</article>\n```\n\nYou can also pass in an object:\n\n```js\nrehype()\n  .use(urls, { transform: removeBaseUrl })\n  .process(input, handleOutput)\n```\n\n### Mutate nodes\n\nIt's also possible to mutate the URL nodes directly. This example will add `target=\"_blank\"` to any external links:\n\n```js\nvar rehype = require('rehype')\nvar urls = require('rehype-urls')\n\nrehype()\n  .use(urls, blankExternal)\n  .process(input, handleOutput)\n\nfunction blankExternal (url, node) {\n  if (url.host !== 'internal.site') {\n    node.properties.target = '_blank'\n  }\n}\n```\n\n## License\n\nApache-2.0\n","readmeFilename":"README.md"}