Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

[trueforge-ui] markdown link should open in new tab (#396)

Shubham Kumar Singhaa4be44f4f38
diff --git a/.changeset/markdown-links-new-tab.md b/.changeset/markdown-links-new-tab.md
new file mode 100644
index 000000000..dfbd0bdcc
--- /dev/null
+++ b/.changeset/markdown-links-new-tab.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge-ui": patch
+---
+
+Open markdown links in assistant messages in a new tab
diff --git a/packages/trueforge-ui/src/atoms/Markdown.tsx b/packages/trueforge-ui/src/atoms/Markdown.tsx
index a3b8f63a8..10d0225cb 100644
--- a/packages/trueforge-ui/src/atoms/Markdown.tsx
+++ b/packages/trueforge-ui/src/atoms/Markdown.tsx
@@ -80,6 +80,14 @@ function makeComponents(opts: {
} = opts;
return {
+ // Chat markdown links should open in a new tab.
+ a({ href, children, node: _node, ...props }) {
+ return (
+ <a {...props} href={href} target="_blank" rel="noopener noreferrer">
+ {children}
+ </a>
+ );
+ },
// Strip default <pre> wrapper — each block renderer provides its own container.
pre({ children }: { children?: ReactNode }) {
return <>{children}</>;
diff --git a/packages/trueforge-ui/test/atoms/Markdown.test.tsx b/packages/trueforge-ui/test/atoms/Markdown.test.tsx
index b1634b914..70b797ba4 100644
--- a/packages/trueforge-ui/test/atoms/Markdown.test.tsx
+++ b/packages/trueforge-ui/test/atoms/Markdown.test.tsx
@@ -29,6 +29,15 @@ describe('Markdown', () => {
expect(strong.closest('.markdown-body')).toBeTruthy();
});
+ it('opens links in a new tab', () => {
+ render(<Markdown content="See [docs](https://example.com/docs) for details." />);
+ const link = screen.getByRole('link', { name: 'docs' });
+ expect(link).toHaveAttribute('href', 'https://example.com/docs');
+ expect(link).toHaveAttribute('target', '_blank');
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer');
+ expect(link).not.toHaveAttribute('node');
+ });
+
it('renders openui fenced blocks via OpenUiFenceBlock', async () => {
render(<Markdown content={'```openui\nCard() { title: "Sales" }\n```'} />);
await waitFor(() => {