remark-transform-links
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

remark-transform-links

npm version npm downloads

transform links in markdown files using remark

📦 Installation

npm install remark-transform-links

🚀 Usage

import { remark } from "remark";
import remarkTransformLinks from "remark-transform-links";

const markdown = `
[Relative Link](/resource.html)
![Relative Image](./image.png)
<a href="/another/path">Link</a>
`;

const result = await remark()
  .use(remarkTransformLinks, { baseUrl: "https://example.com" })
  .process(markdown);

console.log(result.toString());

// Output:
// [Relative Link](https://example.com/resource.html)
// ![Relative Image](https://example.com/image.png)
// <a href="https://example.com/another/path">Link</a>

const result2 = await remark()
  .use(remarkTransformLinks, {
    baseUrl: (path) => {
      if (path.startsWith("/resource.html")) {
        return `https://example.com/market`;
      }

      return `https://example.com`;
    }
  })
  .process(markdown);

console.log(result2.toString());

// Output:
// [Relative Link](https://example.com/market/resource.html)
// ![Relative Image](https://example.com/image.png)
// <a href="https://example.com/another/path">Link</a>

📄 License

Published under MIT License.

Readme

Keywords

Package Sidebar

Install

npm i remark-transform-links

Weekly Downloads

36

Version

0.1.2

License

MIT

Unpacked Size

12.2 kB

Total Files

7

Last publish

Collaborators

  • luxass