11import * as Remarkable from 'remarkable' ;
2- import * as DOMPurify from 'dompurify' ;
2+ import DOMPurify from 'dompurify' ;
33
44import { Html } from '../../types' ;
55
@@ -16,7 +16,9 @@ const linklessMarkdown = new Remarkable({
1616
1717// Add an extra hook to DOMPurify to enforce link target. Without this, DOMPurify strips
1818// every link target entirely.
19- DOMPurify . addHook ( 'afterSanitizeAttributes' , function ( node : Element | HTMLElement ) {
19+ DOMPurify . addHook ( 'afterSanitizeAttributes' , function ( node ) {
20+ if ( ! ( node instanceof Element ) ) return ;
21+
2022 // Closely based on example from https://github.com/cure53/DOMPurify/tree/main/demos#hook-to-open-all-links-in-a-new-window-link
2123
2224 // Set all elements owning target to target=_blank
@@ -36,7 +38,9 @@ DOMPurify.addHook('afterSanitizeAttributes', function (node: Element | HTMLEleme
3638
3739// Add an extra hook to strip relative URLs (markdown largely comes from external sources,
3840// and so should never include relative paths!)
39- DOMPurify . addHook ( 'afterSanitizeAttributes' , function ( node : Element | HTMLElement ) {
41+ DOMPurify . addHook ( 'afterSanitizeAttributes' , function ( node ) {
42+ if ( ! ( node instanceof Element ) ) return ;
43+
4044 if ( node . hasAttribute ( 'href' ) ) {
4145 const target = node . getAttribute ( 'href' ) ;
4246 if ( target ?. startsWith ( '/' ) ) node . removeAttribute ( 'href' ) ;
0 commit comments