@@ -38,9 +38,9 @@ import ThMessage from './TableMessage/ThMessage';
3838import { TableProps } from '@patternfly/react-table' ;
3939import ImageMessage from './ImageMessage/ImageMessage' ;
4040import rehypeUnwrapImages from 'rehype-unwrap-images' ;
41- import { PluggableList } from 'react-markdown/lib' ;
4241import rehypeExternalLinks from 'rehype-external-links' ;
4342import rehypeSanitize from 'rehype-sanitize' ;
43+ import { PluggableList } from 'react-markdown/lib' ;
4444import LinkMessage from './LinkMessage/LinkMessage' ;
4545
4646export interface MessageAttachment {
@@ -167,11 +167,18 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
167167 isLiveRegion = true ,
168168 innerRef,
169169 tableProps,
170- additionalRehypePlugins = [ ] ,
171170 openLinkInNewTab = true ,
171+ additionalRehypePlugins = [ ] ,
172172 ...props
173173} : MessageProps ) => {
174174 const { beforeMainContent, afterMainContent, endContent } = extraContent || { } ;
175+ let rehypePlugins : PluggableList = [ rehypeUnwrapImages ] ;
176+ if ( openLinkInNewTab ) {
177+ rehypePlugins = rehypePlugins . concat ( [ [ rehypeExternalLinks , { target : '_blank' } , rehypeSanitize ] ] ) ;
178+ }
179+ if ( additionalRehypePlugins ) {
180+ rehypePlugins . push ( ...additionalRehypePlugins ) ;
181+ }
175182 let avatarClassName ;
176183 if ( avatarProps && 'className' in avatarProps ) {
177184 const { className, ...rest } = avatarProps ;
@@ -181,16 +188,6 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
181188 // Keep timestamps consistent between Timestamp component and aria-label
182189 const date = new Date ( ) ;
183190 const dateString = timestamp ?? `${ date . toLocaleDateString ( ) } ${ date . toLocaleTimeString ( ) } ` ;
184-
185- const rehypePlugins : PluggableList = [ rehypeUnwrapImages ] ;
186- if ( openLinkInNewTab ) {
187- rehypePlugins . concat ( [ rehypeExternalLinks , { target : '_blank' } , rehypeSanitize ] ) ;
188- }
189- if ( additionalRehypePlugins ) {
190- // should be able to supply a custom sanitization schema this way if needed and apply any other plugins
191- rehypePlugins . concat ( additionalRehypePlugins ) ;
192- }
193-
194191 return (
195192 < section
196193 aria-label = { `Message from ${ role } - ${ dateString } ` }
@@ -258,7 +255,11 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
258255 } ,
259256 th : ( props ) => < ThMessage { ...props } /> ,
260257 img : ( props ) => < ImageMessage { ...props } /> ,
261- a : ( props ) => < LinkMessage { ...props } />
258+ a : ( props ) => (
259+ < LinkMessage href = { props . href } rel = { props . rel } target = { props . target } >
260+ { props . children }
261+ </ LinkMessage >
262+ )
262263 } }
263264 remarkPlugins = { [ remarkGfm ] }
264265 rehypePlugins = { rehypePlugins }
0 commit comments