Update markdown_controller.js

Don't handle links as external by default. Instead distiguish internal (relative) and external (absolute) links.
This commit is contained in:
d-buchmann 2025-05-21 16:47:09 +02:00
parent b8d5b83eee
commit e5a7ddb833

View file

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