Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit ab7505f

Browse files
devversionjelbourn
authored andcommitted
fix: external links with hash are updated incorrectly (#355)
External links with a hash are incorrectly updated, because they are considered as hash links that are referring to a local anchor on the current page (fragment links).
1 parent da929b5 commit ab7505f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/app/shared/doc-viewer/doc-viewer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ export class DocViewer implements OnDestroy {
115115
const anchorElements =
116116
[].slice.call(this._elementRef.nativeElement.querySelectorAll('a')) as HTMLAnchorElement[];
117117

118+
// Update hash links that are referring to the same page and host. Links that are referring
119+
// to a different destination shouldn't be updated. For example the Google Fonts URL.
118120
anchorElements
119-
.filter(anchorEl => anchorEl.hash)
121+
.filter(anchorEl => anchorEl.hash && anchorEl.host === location.host)
120122
.forEach(anchorEl => anchorEl.href = `${baseUrl}${anchorEl.hash}`);
121123
}
122124

0 commit comments

Comments
 (0)