url-convert
0 dependencies. Convert any URL on links, images, scripts, etc to absolute URLs in an HTML source.
Install
npm install url-convert
yarn add url-convert
Usage
; const htmlString = `<div> <a href="/a"></a> <img src="/img" alt="" /> <script src="/script"></script> <link rel="stylesheet" href="./link" /> </div> `;const baseUrl = "https://zenghongtu.com"; ;/*`<div> <a href="https://zenghongtu.com/a"></a> <img src="https://zenghongtu.com/img" alt=""> <script src="https://zenghongtu.com/script"></script> <link rel="stylesheet" href="https://zenghongtu.com/link"> </div> `;*/
; const htmlString = `<div> <a href="/a"></a> <img src="/img" alt="" /> <script src="/script"></script> <link rel="stylesheet" href="./link" /> </div> `;const baseUrl = "https://zenghongtu.com";const handler = { return src + "?raw=true";}; ;/*<div> <a href="https://zenghongtu.com/a?raw=true"></a> <img src="https://zenghongtu.com/img?raw=true" alt=""> <script src="https://zenghongtu.com/script?raw=true"></script> <link rel="stylesheet" href="https://zenghongtu.com/link?raw=true"> </div>*/
License
MIT © zenghongtu