-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renderText): allow custom remark and rehype plugin composition (#…
…2142) Add optional parameters to `renderText()` to enable configuration of rehype and remark plugins used to transform message.text into React elements.
- Loading branch information
1 parent
6ea9ff0
commit 4a25912
Showing
27 changed files
with
748 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import clsx from 'clsx'; | ||
import React, { ComponentProps } from 'react'; | ||
import { ReactMarkdownProps } from 'react-markdown/lib/complex-types'; | ||
|
||
export const Anchor = ({ children, href }: ComponentProps<'a'> & ReactMarkdownProps) => { | ||
const isEmail = href?.startsWith('mailto:'); | ||
const isUrl = href?.startsWith('http'); | ||
|
||
if (!href || (!isEmail && !isUrl)) return <>{children}</>; | ||
|
||
return ( | ||
<a | ||
className={clsx({ 'str-chat__message-url-link': isUrl })} | ||
href={href} | ||
rel='nofollow noreferrer noopener' | ||
target='_blank' | ||
> | ||
{children} | ||
</a> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { ReactMarkdownProps } from 'react-markdown/lib/complex-types'; | ||
|
||
export const Emoji = ({ children }: ReactMarkdownProps) => ( | ||
<span className='inline-text-emoji' data-testid='inline-text-emoji'> | ||
{children} | ||
</span> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
|
||
import type { ReactMarkdownProps } from 'react-markdown/lib/complex-types'; | ||
import type { UserResponse } from 'stream-chat'; | ||
import type { DefaultStreamChatGenerics } from '../../../types/types'; | ||
|
||
export type MentionProps< | ||
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics | ||
> = ReactMarkdownProps & { | ||
/** | ||
* @deprecated will be removed in the next major release, transition to using `node.mentionedUser` instead | ||
*/ | ||
mentioned_user: UserResponse<StreamChatGenerics>; | ||
node: { | ||
/** | ||
* @deprecated will be removed in the next major release, transition to using `node.mentionedUser` instead | ||
*/ | ||
mentioned_user: UserResponse<StreamChatGenerics>; | ||
mentionedUser: UserResponse<StreamChatGenerics>; | ||
}; | ||
}; | ||
export const Mention = < | ||
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics | ||
>({ | ||
children, | ||
node: { mentionedUser }, | ||
}: MentionProps<StreamChatGenerics>) => ( | ||
<span className='str-chat__message-mention' data-user-id={mentionedUser.id}> | ||
{children} | ||
</span> | ||
); |
File renamed without changes.
Oops, something went wrong.