{"id":15013630,"url":"https://github.com/rjanjic/remark-link-rewrite","last_synced_at":"2026-03-17T02:48:49.028Z","repository":{"id":59473328,"uuid":"537371481","full_name":"rjanjic/remark-link-rewrite","owner":"rjanjic","description":"Remark Link Rewrite Plugin","archived":false,"fork":false,"pushed_at":"2023-11-10T18:05:32.000Z","size":12,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T00:22:44.077Z","etag":null,"topics":["md","mdx","mdx-js","remark","remark-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rjanjic.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}},"created_at":"2022-09-16T08:30:01.000Z","updated_at":"2025-03-11T21:55:08.000Z","dependencies_parsed_at":"2023-01-18T14:16:00.924Z","dependency_job_id":null,"html_url":"https://github.com/rjanjic/remark-link-rewrite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjanjic%2Fremark-link-rewrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjanjic%2Fremark-link-rewrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjanjic%2Fremark-link-rewrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjanjic%2Fremark-link-rewrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjanjic","download_url":"https://codeload.github.com/rjanjic/remark-link-rewrite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248519473,"owners_count":21117757,"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":["md","mdx","mdx-js","remark","remark-plugin"],"created_at":"2024-09-24T19:44:35.215Z","updated_at":"2026-03-17T02:48:43.992Z","avatar_url":"https://github.com/rjanjic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Remark Link Rewrite Plugin\n\nThe Remark Link Rewrite Plugin is a utility for the Remark processor that enables you to customize link URLs dynamically. You can use it to change the domain of links, modify file extensions, or apply any other transformation required by your specific use case.\n\n## Requirements\n\nThis package uses ECMAScript modules (ESM) and requires Node.js versions 12.20+, 14.14+, or 16.0+.\n\n## Installation\n\nThis package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:\n\n```bash\nnpm install remark-link-rewrite\n```\n\n## Basic Usage\n\nHere's a simple example of how to use the plugin to replace links that start with `https://example.com` to `https://example.org`.\n\n```javascript\nimport { remark } from 'remark';\nimport RemarkLinkRewrite from 'remark-link-rewrite';\n\nremark()\n  .use(RemarkLinkRewrite, {\n    replacer: (url) =\u003e {\n      if (url.startsWith('https://example.com')) {\n        return url.replace('https://example.com', 'https://example.org')\n      }\n      return url\n    }\n  })\n  .process('[Example](https://example.com)')\n  .then(({ value }) =\u003e {\n    console.log(String(value))\n  });\n```\n\n## Usage with Asynchronous Replacer\n\nYou can also use the plugin with an asynchronous replacer function. Here's an example where the replacer fetches a new URL from an API or a database.\n\n```javascript\nimport { remark } from 'remark';\nimport RemarkLinkRewrite from 'remark-link-rewrite';\n\n// example async function to fetch a URL from an API or database\nasync function fetchFromAPI(url) {\n  return 'https://example.org'\n\n  // example:\n  // const response = await fetch('/my-api', {\n  //   method: 'POST',\n  //   body: JSON.stringify({ url }),\n  //   headers: {\n  //     'Content-Type': 'application/json'\n  //   }\n  // })\n  // return response.url\n}\n\nremark()\n  .use(RemarkLinkRewrite, {\n    replacer: async (url) =\u003e {\n      if (url.startsWith('https://example.com')) {\n        const resolvedURL = await fetchFromAPI(url);\n        return url.replace('https://example.com', resolvedURL);\n      }\n      return url\n    }\n  })\n  .process('[Example](https://example.com)')\n  .then(({ value }) =\u003e {\n    console.log(String(value))\n  });\n```\n\n## Options\n\n- `replacer`: A function that receives a URL and returns a new URL. It gets called for every link in the document. This function can be synchronous or asynchronous.\n\n## License\n\n[MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjanjic%2Fremark-link-rewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjanjic%2Fremark-link-rewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjanjic%2Fremark-link-rewrite/lists"}