Skip to content

Commit 993e5ef

Browse files
author
Amin Mahboubi
authored
fix #569: add nofollow noreferrer noopener to links markdown (#570)
1 parent d089db7 commit 993e5ef

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/utils.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ export const truncate = (input, length, end = '...') => {
146146
return input;
147147
};
148148

149+
const markDownRenderers = {
150+
/** @param {{ href: string | undefined; children: React.ReactNode; }} props */
151+
link: (props) => {
152+
if (!props.href || !props.href.startsWith('http')) return props.children; // could cause issue for app:// links?
153+
return (
154+
<a href={props.href} target="_blank" rel="nofollow noreferrer noopener">
155+
{props.children}
156+
</a>
157+
);
158+
},
159+
};
160+
149161
/** @type {(input: string | undefined, mentioned_users: import('stream-chat').UserResponse[] | undefined) => React.ReactNode} */
150162
export const renderText = (text, mentioned_users) => {
151163
// take the @ mentions and turn them into markdown?
@@ -182,8 +194,8 @@ export const renderText = (text, mentioned_users) => {
182194
<ReactMarkdown
183195
allowedTypes={allowedMarkups}
184196
source={newText}
185-
linkTarget="_blank"
186-
plugins={[]}
197+
// @ts-ignore
198+
renderers={markDownRenderers}
187199
escapeHtml={true}
188200
skipHtml={false}
189201
unwrapDisallowed={true}

0 commit comments

Comments
 (0)