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,6 +56,9 @@ export default class MarkdownController extends Controller {
this.element.innerHTML = DOMPurify.sanitize(MarkdownController._marked.parse(this.unescapeHTML(raw)));
for(let a of this.element.querySelectorAll('a')) {
// test if link is absolute
var r = new RegExp('^(?:[a-z+]+:)?//', 'i');
if (r.test(a.getAttribute('href'))) {
//Mark all links as external
a.classList.add('link-external');
//Open links in new tag
@ -63,6 +66,7 @@ export default class MarkdownController extends Controller {
//Dont track
a.setAttribute('rel', 'noopener');
}
}
//Apply bootstrap styles to tables
for(let table of this.element.querySelectorAll('table')) {