Skip to content

Commit a940eb3

Browse files
committed
fix: removed large spacing between elements in rendered markdown
1 parent fe50b5e commit a940eb3

5 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/components/BotMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function BotMessage({ message, isLoading }: BotMessageProps) {
6161
<Copy className="h-4 w-4" aria-hidden="true" />
6262
<span className="sr-only">Copy</span>
6363
</button>
64-
<div className="prose prose-sm dark:prose-invert max-w-none break-words break-all whitespace-pre-wrap">
64+
<div className="prose prose-sm dark:prose-invert">
6565
<MarkdownContent content={message.content} />
6666
</div>
6767
</div>

src/components/MarkdownContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type MarkdownContentProps = {
77

88
export function MarkdownContent({ content }: MarkdownContentProps) {
99
return (
10-
<div className="prose prose-sm dark:prose-invert max-w-none break-words">
10+
<div className="prose prose-sm dark:prose-invert max-w-none break-words [&>*+*]:mt-4 [&>h1+*]:mt-3 [&>h2+*]:mt-3 [&>h3+*]:mt-3 [&>p+ul]:mt-3 [&>p+ol]:mt-3">
1111
<ReactMarkdown
1212
remarkPlugins={[remarkGfm]}
1313
components={{

src/components/ReasoningMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function ReasoningMessage({
8383
<div className="text-xs space-y-1 mt-1">
8484
{effort && <div>Effort: {effort}</div>}
8585
{summary && (
86-
<div className="prose prose-sm dark:prose-invert max-w-none break-words break-all whitespace-pre-wrap">
86+
<div className="prose prose-sm dark:prose-invert">
8787
<MarkdownContent content={summary} />
8888
</div>
8989
)}

src/components/UserMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function UserMessage({ message }: UserMessageProps) {
3232
'rounded-2xl px-4 py-2 text-sm w-full bg-gray-100 text-gray-900 dark:bg-gray-800 dark:text-gray-100',
3333
)}
3434
>
35-
<div className="prose prose-sm dark:prose-invert max-w-none break-words break-all whitespace-pre-wrap">
35+
<div className="prose prose-sm dark:prose-invert">
3636
<MarkdownContent content={message.content} />
3737
</div>
3838
</div>

src/routes/api/chat.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,29 @@ export const ServerRoute = createServerFileRoute('/api/chat').methods({
6464
},
6565
})) satisfies Tool[]
6666

67+
// System prompt for proper markdown formatting
68+
const systemPrompt = `You are a helpful AI assistant that communicates using properly formatted markdown. Follow these strict formatting rules:
69+
70+
MARKDOWN FORMATTING REQUIREMENTS:
71+
1. **Lists**: Always keep list items on the same line as the marker
72+
- ✅ CORRECT: "1. Lorem ipsum dolor sit amet..."
73+
- ❌ WRONG: "1. \\nLorem ipsum dolor sit amet..."
74+
75+
2. **No line breaks after list markers**: Never put a line break immediately after numbered lists (1. 2. 3.) or bullet lists (- * +)
76+
77+
3. **Proper list syntax**:
78+
- Numbered lists: "1. Content here"
79+
- Bullet lists: "- Content here" or "* Content here"
80+
- No extra spaces or line breaks between marker and content
81+
82+
4. **Other markdown**: Use standard markdown for headers, emphasis, links, tables, and code blocks
83+
84+
5. **Consistency**: Maintain consistent formatting throughout your response
85+
86+
Remember: Keep list content on the same line as the list marker to ensure proper rendering.`
87+
6788
// Format the conversation history into a single input string with proper message parts
68-
const input = messages
89+
const conversationHistory = messages
6990
.map((msg) => ({
7091
role: msg.role,
7192
parts: [
@@ -81,6 +102,9 @@ export const ServerRoute = createServerFileRoute('/api/chat').methods({
81102
)
82103
.join('\n\n')
83104

105+
// Combine system prompt with conversation
106+
const input = `${systemPrompt}\n\n--- CONVERSATION ---\n\n${conversationHistory}`
107+
84108
const client = new OpenAI()
85109

86110
let answer

0 commit comments

Comments
 (0)