1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { useNavigate } from 'react-router-dom';
5 const RawHTML = ({ html }) => {
6 const navigate = useNavigate();
9 if (e.defaultPrevented) return;
10 if (e.metaKey || e.ctrlKey || e.shiftKey) return;
11 if (e.button !== 0) return;
14 while (el && el.nodeName !== 'A') {
19 if (el.target && el.target !== '_self') return;
20 if (el.attributes.download) return;
21 if (el.rel && /(?:^|\s+)external(?:\s+|$)/.test(el.rel)) return;
23 const href = el.getAttribute('href');
25 if (href.startsWith('#')) return;
26 if (href.startsWith('http')) return;
27 if (href.startsWith('mailto')) return;
28 if (href.startsWith('tel')) return;
34 // scroll to top on location change
35 scrollTo({ top: 0, behavior: 'smooth' });
41 return <div onClick={onClick} dangerouslySetInnerHTML={{ __html: html }} />;
45 html: PropTypes.string,
48 export default RawHTML;