From 2d04f0165d2adfc26bf7f492a937fc72fcb784c2 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Sat, 3 Jun 2023 13:07:54 +0200 Subject: [PATCH] markdown parser: allow setting target tag for links If one really want's to force a link to open in a new tab (or window, depending on the browser settings). Note that we don't set target to _blank by default for links, as opening in a new tab can already simply be done via a middle-click on the link without that, but once the target is set opening in the same tab cannot easily be done, i.e., without a target set the reader has more freedom and flexibility. Signed-off-by: Thomas Lamprecht --- src/Parser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Parser.js b/src/Parser.js index 08e2502..2d126da 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -26,7 +26,7 @@ Ext.define('Proxmox.Markdown', { const value = node.attributes[i].value; // TODO: we may want to also disallow class and id attrs if ( - !/^(class|id|name|href|src|alt|align|valign|disabled|checked|start|type)$/i.test(name) + !/^(class|id|name|href|src|alt|align|valign|disabled|checked|start|type|target)$/i.test(name) ) { node.attributes.removeNamedItem(name); } else if ((name === 'href' || name === 'src') && !_isHTTPLike(value)) { @@ -44,6 +44,8 @@ Ext.define('Proxmox.Markdown', { } catch (e) { node.attributes.removeNamedItem(name); } + } else if (name === 'target' && node.tagName.toLowerCase() !== 'a') { + node.attributes.removeNamedItem(name); } } for (let i=node.childNodes.length; i--;) _sanitize(node.childNodes[i]);