Skip to content

Commit

Permalink
fix #569: add nofollow noreferrer noopener to links markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mahboubii committed Oct 12, 2020
1 parent d089db7 commit 9492763
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ export const truncate = (input, length, end = '...') => {
return input;
};

const markDownRenderers = {
/** @param {{ href: string | undefined; children: React.ReactNode; }} props */
link: (props) => {
if (!props.href || !props.href.startsWith('http')) return props.children; // could cause issue for app:// links?
return (
<a href={props.href} target="_blank" rel="nofollow noreferrer noopener">
{props.children}
</a>
);
},
};

/** @type {(input: string | undefined, mentioned_users: import('stream-chat').UserResponse[] | undefined) => React.ReactNode} */
export const renderText = (text, mentioned_users) => {
// take the @ mentions and turn them into markdown?
Expand Down Expand Up @@ -182,8 +194,8 @@ export const renderText = (text, mentioned_users) => {
<ReactMarkdown
allowedTypes={allowedMarkups}
source={newText}
linkTarget="_blank"
plugins={[]}
// @ts-ignore
renderers={markDownRenderers}
escapeHtml={true}
skipHtml={false}
unwrapDisallowed={true}
Expand Down

0 comments on commit 9492763

Please sign in to comment.