mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 14:29:48 +02:00
fix: target blank removed from anchor tag
This commit is contained in:
@@ -28,6 +28,21 @@ export const removeScript = (txt: string): string => {
|
||||
return DOMPurify.sanitize(txt);
|
||||
};
|
||||
|
||||
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
|
||||
// set all elements owning target to target=_blank
|
||||
if ('target' in node) {
|
||||
node.setAttribute('target', '_blank');
|
||||
node.setAttribute('rel', 'noopener noreferrer');
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
});
|
||||
|
||||
const sanitizeMore = (text: string, config: MermaidConfig) => {
|
||||
if (config.flowchart?.htmlLabels !== false) {
|
||||
const level = config.securityLevel;
|
||||
|
Reference in New Issue
Block a user