]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
markdown parser: allow setting target tag for links
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 3 Jun 2023 11:07:54 +0000 (13:07 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 3 Jun 2023 11:41:23 +0000 (13:41 +0200)
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>
src/Parser.js

index 08e2502e0dc99ec154cc338ae66d518396af7b79..2d126da8fc95a68cfdec3172953e48576a897b0e 100644 (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]);