Skip to content

Commit

Permalink
Backport PR #474: Make links from Jupyter AI chat open in new tab (vs…
Browse files Browse the repository at this point in the history
… in the same tab currently) (#476)

Co-authored-by: Andrii Ieroshenko <[email protected]>
  • Loading branch information
meeseeksmachine and andrii-i authored Nov 17, 2023
1 parent b39c073 commit fc5bccb
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 fc5bccb

Please sign in to comment.