{"id":20570082,"url":"https://github.com/brechtcs/rehype-urls","last_synced_at":"2025-04-14T16:42:04.509Z","repository":{"id":57352568,"uuid":"160701911","full_name":"brechtcs/rehype-urls","owner":"brechtcs","description":"Rehype plugin to rewrite URLs","archived":false,"fork":false,"pushed_at":"2023-07-19T18:57:25.000Z","size":11,"stargazers_count":14,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T05:24:35.116Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brechtcs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-06T16:29:33.000Z","updated_at":"2024-07-08T01:48:04.000Z","dependencies_parsed_at":"2024-06-18T18:32:18.036Z","dependency_job_id":null,"html_url":"https://github.com/brechtcs/rehype-urls","commit_stats":{"total_commits":7,"total_committers":4,"mean_commits":1.75,"dds":0.4285714285714286,"last_synced_commit":"9aaf6d11eaf4352034b916ee639f47f06c6a90a3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brechtcs%2Frehype-urls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brechtcs%2Frehype-urls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brechtcs%2Frehype-urls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brechtcs%2Frehype-urls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brechtcs","download_url":"https://codeload.github.com/brechtcs/rehype-urls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248506171,"owners_count":21115390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T05:11:24.738Z","updated_at":"2025-04-14T16:42:04.481Z","avatar_url":"https://github.com/brechtcs.png","language":"JavaScript","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\u003carticle\u003e\n  \u003cimg src=\"http://internal.site/image.jpg\"\u003e\n  \u003ca href=\"http://internal.site/page.html\"\u003epage\u003c/a\u003e\n  \u003ca href=\"http://example.com\"\u003elink\u003c/a\u003e\n\u003c/article\u003e\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\u003carticle\u003e\n  \u003cimg src=\"/image.jpg\"\u003e\n  \u003ca href=\"/page.html\"\u003epage\u003c/a\u003e\n  \u003ca href=\"http://example.com\"\u003elink\u003c/a\u003e\n\u003c/article\u003e\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrechtcs%2Frehype-urls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrechtcs%2Frehype-urls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrechtcs%2Frehype-urls/lists"}