Skip to content

Commit

Permalink
BREAKING CHANGE: Adds base to all absolute links
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanM04 committed Feb 8, 2023
1 parent b35a627 commit f0c9617
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/node/markdown/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ export const linkPlugin = (
pushLink(url, env)
}
hrefAttr[1] = url.replace(PATHNAME_PROTOCOL_RE, '')
} else if (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {
normalizeHref(hrefAttr, env)
} else {
if (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {
normalizeHref(hrefAttr, env)
}

// append base to internal (non-relative) urls
if (hrefAttr[1].startsWith('/')) {
hrefAttr[1] = `${base}${hrefAttr[1]}`.replace(/\/+/g, '/')
}
}

// encode vite-specific replace strings in case they appear in URLs
Expand Down Expand Up @@ -90,11 +97,6 @@ export const linkPlugin = (
// export it for existence check
pushLink(url.replace(/\.html$/, ''), env)

// append base to internal (non-relative) urls
if (url.startsWith('/')) {
url = `${base}${url}`.replace(/\/+/g, '/')
}

// markdown-it encodes the uri
hrefAttr[1] = decodeURI(url)
}
Expand Down

0 comments on commit f0c9617

Please sign in to comment.