Skip to content

Commit

Permalink
Make MD links in chat msgs open in new tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Nov 16, 2023
1 parent 2c89d13 commit 5aaa6c6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/jupyter-ai/src/components/chat-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ type ChatMessageHeaderProps = {
sx?: SxProps<Theme>;
};

type NewTabLinkProps = {
children: React.ReactNode;
href?: string;
};

export function ChatMessageHeader(props: ChatMessageHeaderProps): JSX.Element {
const collaborators = useCollaboratorsContext();

Expand Down Expand Up @@ -128,6 +133,14 @@ export function ChatMessages(props: ChatMessagesProps): JSX.Element {
}
}, [props.messages]);

function NewTabLink(props: NewTabLinkProps) {
return (
<a href={props.href ?? '#'} target="_blank" rel="noopener noreferrer">
{props.children}
</a>
);
}

return (
<Box
sx={{
Expand All @@ -149,6 +162,7 @@ export function ChatMessages(props: ChatMessagesProps): JSX.Element {
// markdown styling and then overriding any CSS to make it more compact.
className="jp-RenderedHTMLCommon jp-ai-react-markdown"
components={{
a: NewTabLink,
code: ChatCodeView
}}
remarkPlugins={[remarkMath]}
Expand Down

0 comments on commit 5aaa6c6

Please sign in to comment.