Skip to content

Commit

Permalink
Treat links under hostedBaseUrl as internal
Browse files Browse the repository at this point in the history
Resolves #2809
  • Loading branch information
Gerrit0 committed Dec 14, 2024
1 parent 8acc237 commit d9ec2dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ title: Changelog
- Fix restoration of groups/categories including documents, #2801.
- Fixed missed relative paths within markdown link references in documents.
- Improved handling of incomplete inline code blocks within markdown.
- Direct `https://` links under the `hostedBaseUrl` option's URL will no
longer be treated as external, #2809.

### Thanks!

Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
*/
protected urlPrefix = /^(http|ftp)s?:\/\//;

private get hostedBaseUrl() {
protected get hostedBaseUrl() {
const url = this.application.options.getValue("hostedBaseUrl");
return !url || url.endsWith("/") ? url : url + "/";
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/output/themes/MarkedPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ export class MarkedPlugin extends ContextAwareRendererComponent {
// will be relative links. This will likely have to change with
// the introduction of support for customized routers whenever
// that becomes a real thing.
if (this.markdownLinkExternal && /https?:\/\//i.test(href)) {
if (
this.markdownLinkExternal &&
/https?:\/\//i.test(href) &&
!(href + "/").startsWith(this.hostedBaseUrl)
) {
token.attrSet("target", "_blank");
const classes = token.attrGet("class")?.split(" ") || [];
classes.push("external");
Expand Down

0 comments on commit d9ec2dd

Please sign in to comment.