External links
This commit is contained in:
17
rehype/external-links.js
Normal file
17
rehype/external-links.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import {visit} from 'unist-util-visit'
|
||||
|
||||
export default () => {
|
||||
return (tree) => {
|
||||
visit(tree, 'element', function (node) {
|
||||
if (
|
||||
node.tagName === 'a' &&
|
||||
typeof node.properties.href === 'string'
|
||||
) {
|
||||
const url = node.properties.href
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
node.properties.target = '_blank'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user