Skip to content

Commit

Permalink
Merge pull request #78 from funkycram/enh/only-use-_blank-on-external…
Browse files Browse the repository at this point in the history
…-richtext-links

Enh #61: Only use _blank on external richtext links
  • Loading branch information
luke- authored Sep 6, 2022
2 parents 1253f32 + 6243a23 commit 21839bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Changelog
- Fix #32: Disallow marks in code block schema
- Fix #41: Overflow detection broken
- Fix #36: resize nav state does not respect selection state
- Enh #61: Only use _blank on external richtext links (https://github.com/humhub/humhub/issues/3989)


1.1.2 (February 18, 2021)
Expand Down
6 changes: 5 additions & 1 deletion src/editor/core/plugins/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const link = {
var aIndex = tokens[idx].attrIndex('target');

if (aIndex < 0) {
tokens[idx].attrPush(['target', '_blank']); // add new attribute
// Check if the link is external
var hrefUrl = new URL(tokens[idx].attrs[hrefIndex][1]);
if (hrefUrl.hostname !== window.location.hostname) {
tokens[idx].attrPush(['target', '_blank']); // add new attribute
}
} else if(!tokens[idx].attrs[aIndex][1]) {
tokens[idx].attrs[aIndex][1] = '_blank'; // replace value of existing attr
}
Expand Down

0 comments on commit 21839bc

Please sign in to comment.