fix: added type Element to the node used in callback in the addhook function

This commit is contained in:
Harshit Anand 2023-10-23 12:03:57 +05:30
parent 345e82abee
commit 111e067df5

View File

@ -30,21 +30,21 @@ export const removeScript = (txt: string): string => {
const TEMPORARY_ATTRIBUTE = 'data-temp-href-target'; const TEMPORARY_ATTRIBUTE = 'data-temp-href-target';
DOMPurify.addHook('beforeSanitizeAttributes', function (node) { // DOMPurify.addHook('beforeSanitizeAttributes', (node: Element) => {
if (node.tagName === 'A' && node.hasAttribute('target')) { // if (node.tagName === 'A' && node.hasAttribute('target')) {
node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') || ''); // node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') || '');
} // }
}); // });
DOMPurify.addHook('afterSanitizeAttributes', function (node) { // DOMPurify.addHook('afterSanitizeAttributes', (node: Element) => {
if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) { // if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) || ''); // node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) || '');
node.removeAttribute(TEMPORARY_ATTRIBUTE); // node.removeAttribute(TEMPORARY_ATTRIBUTE);
if (node.getAttribute('target') === '_blank') { // if (node.getAttribute('target') === '_blank') {
node.setAttribute('rel', 'noopener'); // node.setAttribute('rel', 'noopener');
} // }
} // }
}); // });
const sanitizeMore = (text: string, config: MermaidConfig) => { const sanitizeMore = (text: string, config: MermaidConfig) => {
if (config.flowchart?.htmlLabels !== false) { if (config.flowchart?.htmlLabels !== false) {