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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-06-03 13:07:54 +02:00
parent 5cbbb9c44a
commit 2d04f0165d

View File

@ -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]);