Do not mark internal (relative) links as external and open in new tab in markdown blocks
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run

Don't handle links as external by default. Instead distiguish internal (relative) and external (absolute) links.
This commit is contained in:
d-buchmann 2025-09-06 19:49:38 +02:00 committed by GitHub
parent 4e9e82d9f1
commit 0e9558e331
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,12 +56,16 @@ export default class MarkdownController extends Controller {
this.element.innerHTML = DOMPurify.sanitize(MarkdownController._marked.parse(this.unescapeHTML(raw))); this.element.innerHTML = DOMPurify.sanitize(MarkdownController._marked.parse(this.unescapeHTML(raw)));
for(let a of this.element.querySelectorAll('a')) { for(let a of this.element.querySelectorAll('a')) {
//Mark all links as external // test if link is absolute
a.classList.add('link-external'); var r = new RegExp('^(?:[a-z+]+:)?//', 'i');
//Open links in new tag if (r.test(a.getAttribute('href'))) {
a.setAttribute('target', '_blank'); //Mark all links as external
//Dont track a.classList.add('link-external');
a.setAttribute('rel', 'noopener'); //Open links in new tag
a.setAttribute('target', '_blank');
//Dont track
a.setAttribute('rel', 'noopener');
}
} }
//Apply bootstrap styles to tables //Apply bootstrap styles to tables
@ -108,4 +112,4 @@ export default class MarkdownController extends Controller {
gfm: true, gfm: true,
}); });
}*/ }*/
} }