
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
rehype-urls
Advanced tools
Rehype plugin to rewrite URLs of href
and src
attributes.
npm install rehype-urls
Given this markup:
<article>
<img src="http://internal.site/image.jpg">
<a href="http://internal.site/page.html">page</a>
<a href="http://example.com">link</a>
</article>
You can use the following script:
var rehype = require('rehype')
var urls = require('rehype-urls')
rehype()
.use(urls, removeBaseUrl)
.process(input, handleOutput)
function removeBaseUrl (url) {
if (url.host === 'internal.site') {
return url.path
}
}
Which will transform it into:
<article>
<img src="/image.jpg">
<a href="/page.html">page</a>
<a href="http://example.com">link</a>
</article>
You can also pass in an object:
rehype()
.use(urls, { transform: removeBaseUrl })
.process(input, handleOutput)
It's also possible to mutate the URL nodes directly. This example will add target="_blank"
to any external links:
var rehype = require('rehype')
var urls = require('rehype-urls')
rehype()
.use(urls, blankExternal)
.process(input, handleOutput)
function blankExternal (url, node) {
if (url.host !== 'internal.site') {
node.properties.target = '_blank'
}
}
Apache-2.0
FAQs
Rehype plugin to rewrite URLs of `href` and `src` attributes
The npm package rehype-urls receives a total of 3,788 weekly downloads. As such, rehype-urls popularity was classified as popular.
We found that rehype-urls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.