mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
fix: Prevent tabnabbing in markdown
This commit is contained in:
parent
d355cd9d57
commit
f8720b8020
1 changed files with 17 additions and 10 deletions
|
@ -6,6 +6,8 @@ import remarkBreaks from 'remark-breaks';
|
||||||
|
|
||||||
import './Markdown.module.scss'; // FIXME: import as styles?
|
import './Markdown.module.scss'; // FIXME: import as styles?
|
||||||
|
|
||||||
|
const ABSOLUTE_URL_REGEX = /^(?:https?:)?\/\//i;
|
||||||
|
|
||||||
const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
||||||
const handleLinkClick = useCallback((event) => {
|
const handleLinkClick = useCallback((event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
@ -16,25 +18,30 @@ const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
||||||
jsx-a11y/click-events-have-key-events,
|
jsx-a11y/click-events-have-key-events,
|
||||||
jsx-a11y/no-static-element-interactions,
|
jsx-a11y/no-static-element-interactions,
|
||||||
react/jsx-props-no-spreading */
|
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,
|
/* eslint-enable jsx-a11y/anchor-has-content,
|
||||||
jsx-a11y/click-events-have-key-events,
|
jsx-a11y/click-events-have-key-events,
|
||||||
jsx-a11y/no-static-element-interactions,
|
jsx-a11y/no-static-element-interactions,
|
||||||
react/jsx-props-no-spreading */
|
react/jsx-props-no-spreading */
|
||||||
[handleLinkClick],
|
[linkStopPropagation, handleLinkClick],
|
||||||
);
|
);
|
||||||
|
|
||||||
let components;
|
|
||||||
if (linkStopPropagation) {
|
|
||||||
components = {
|
|
||||||
a: linkRenderer,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
||||||
components={components}
|
components={{
|
||||||
|
a: linkRenderer,
|
||||||
|
}}
|
||||||
remarkPlugins={[remarkGfm, remarkBreaks]}
|
remarkPlugins={[remarkGfm, remarkBreaks]}
|
||||||
className="markdown-body"
|
className="markdown-body"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue