From 2936bbb4efd47d9349d77900cb2c45828758930d Mon Sep 17 00:00:00 2001 From: poyrazavsever Date: Tue, 9 Jun 2026 15:16:10 +0300 Subject: [PATCH] feat: add markdown-like text formatting for bold and italic syntax in chat messages --- app/(dashboard)/chat/page.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/(dashboard)/chat/page.tsx b/app/(dashboard)/chat/page.tsx index c7d5d06..49e66ec 100644 --- a/app/(dashboard)/chat/page.tsx +++ b/app/(dashboard)/chat/page.tsx @@ -8,6 +8,29 @@ import { Button } from "poyraz-ui/atoms"; import { useEffect, useRef, useState } from "react"; import { toast } from "poyraz-ui/molecules"; +function formatMessageContent(text: string) { + if (!text) return null; + const lines = text.split("\n"); + return lines.map((line, i) => ( + + {line.split(/(\*\*.*?\*\*|\*.*?\*)/g).map((part, j) => { + if (part.startsWith("**") && part.endsWith("**")) { + return ( + + {part.slice(2, -2)} + + ); + } + if (part.startsWith("*") && part.endsWith("*")) { + return {part.slice(1, -1)}; + } + return {part}; + })} + {i !== lines.length - 1 &&
} +
+ )); +} + type ChatSession = { id: string; title: string; @@ -225,7 +248,7 @@ export default function AIChatPage() { : "border border-border bg-muted/40 text-foreground" }`} > - {text} + {formatMessageContent(text)} );