mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-12-27 01:42:11 +08:00
Fix absolute URL detection when traversing markdown links (#1255)
This commit is contained in:
parent
bf6823240b
commit
510f657542
1 changed files with 8 additions and 3 deletions
|
@ -134,13 +134,18 @@ function remarkExpandUrls(options) {
|
|||
return (ast) => {
|
||||
if (options.baseUrl) {
|
||||
visit(ast, "link", (node) => {
|
||||
if (node.url && !isAbsoluteUrl(node.url) && !isPageAnchor(node.url)) {
|
||||
if (
|
||||
node.url &&
|
||||
!isAbsoluteUrl(node.url) &&
|
||||
!isInternalUrl(node.url) &&
|
||||
!isPageAnchor(node.url)
|
||||
) {
|
||||
node.url = urlAppend(options.baseUrl, node.url);
|
||||
}
|
||||
});
|
||||
|
||||
visit(ast, "image", (node) => {
|
||||
if (node.url && !isAbsoluteUrl(node.url)) {
|
||||
if (node.url && !isAbsoluteUrl(node.url) && !isInternalUrl(node.url)) {
|
||||
node.url = urlAppend(options.baseUrl, node.url);
|
||||
}
|
||||
});
|
||||
|
@ -220,7 +225,7 @@ function rehypeExternalLinks(options) {
|
|||
}
|
||||
|
||||
function isAbsoluteUrl(url) {
|
||||
return url.startsWith("http") || url.startsWith("/");
|
||||
return /^(?:[a-z]+:)?\/\//i.test(url);
|
||||
}
|
||||
|
||||
function isPageAnchor(url) {
|
||||
|
|
Loading…
Reference in a new issue