|
|
|
|
@ -6,6 +6,8 @@ import remarkBreaks from 'remark-breaks';
|
|
|
|
|
|
|
|
|
|
import './Markdown.module.scss'; // FIXME: import as styles?
|
|
|
|
|
|
|
|
|
|
const ABSOLUTE_URL_REGEX = /^(?:https?:)?\/\//i;
|
|
|
|
|
|
|
|
|
|
const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
|
|
|
|
const handleLinkClick = useCallback((event) => {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
@ -16,25 +18,30 @@ const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
|
|
|
|
jsx-a11y/click-events-have-key-events,
|
|
|
|
|
jsx-a11y/no-static-element-interactions,
|
|
|
|
|
react/jsx-props-no-spreading */
|
|
|
|
|
({ node, ...linkProps }) => <a {...linkProps} onClick={handleLinkClick} />,
|
|
|
|
|
({ node, ...linkProps }) => (
|
|
|
|
|
<a
|
|
|
|
|
{...linkProps}
|
|
|
|
|
rel={
|
|
|
|
|
ABSOLUTE_URL_REGEX.test(linkProps.href) && linkProps.target === '_blank'
|
|
|
|
|
? 'noreferrer'
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
onClick={linkStopPropagation ? handleLinkClick : undefined}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
/* eslint-enable jsx-a11y/anchor-has-content,
|
|
|
|
|
jsx-a11y/click-events-have-key-events,
|
|
|
|
|
jsx-a11y/no-static-element-interactions,
|
|
|
|
|
react/jsx-props-no-spreading */
|
|
|
|
|
[handleLinkClick],
|
|
|
|
|
[linkStopPropagation, handleLinkClick],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let components;
|
|
|
|
|
if (linkStopPropagation) {
|
|
|
|
|
components = {
|
|
|
|
|
a: linkRenderer,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
|
|
|
|
components={components}
|
|
|
|
|
components={{
|
|
|
|
|
a: linkRenderer,
|
|
|
|
|
}}
|
|
|
|
|
remarkPlugins={[remarkGfm, remarkBreaks]}
|
|
|
|
|
className="markdown-body"
|
|
|
|
|
/>
|
|
|
|
|
|