0.1.2 • Published 5 months ago
remark-transform-links v0.1.2
remark-transform-links
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)

<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)
// 
// <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)
// 
// <a href="https://example.com/another/path">Link</a>
📄 License
Published under MIT License.