From 221cf8519ae346afb68e8d9410b0a3047f858b5b Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Tue, 28 Jul 2020 09:49:43 +0100 Subject: [PATCH] open html links in a new tab --- template/static/javascripts/app.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/template/static/javascripts/app.js b/template/static/javascripts/app.js index 6b94bb0..7b22629 100644 --- a/template/static/javascripts/app.js +++ b/template/static/javascripts/app.js @@ -1,5 +1,19 @@ 'use strict'; +DOMPurify.addHook('afterSanitizeAttributes', function (node) { + // set all elements owning target to target=_blank + if ('target' in node) { + node.setAttribute('target', '_blank'); + } + // set non-HTML/MathML links to xlink:show=new + if ( + !node.hasAttribute('target') && + (node.hasAttribute('xlink:href') || node.hasAttribute('href')) + ) { + node.setAttribute('xlink:show', 'new'); + } +}); + Vue.prototype.$sanitize = DOMPurify.sanitize var debounce = function(callback, wait) {