0.1.2 • Published 5 months ago

remark-transform-links v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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.

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago

0.0.0

5 months ago