xonecas.io
53129
Pa

PAT / commit de1bf61

fix: markdown rendering by tailwind

xonecas2025-12-16 de1bf61566003685762b007956314efdeadddfe7 parent dfaa4ea

8 files changed

AGENTS.md+9−4
@@ -26,6 +26,7 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
2626 - **react**: 18.2.0 - React library
2727 - **react-dom**: 18.2.0 - React DOM rendering
2828 - **tailwindcss**: ^3.4.0 - Utility-first CSS framework
29+- **@tailwindcss/typography**: ^0.5.x - Tailwind CSS plugin for beautiful typographic defaults
2930 - **typescript**: ^5.4.2 - TypeScript compiler
3031 - **ollama**: ^0.6.3 - Official Ollama npm package for model interaction
3132 - **autoprefixer**: ^10.4.17 - CSS post-processor
@@ -100,6 +101,10 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
100101 - Use responsive design utilities when appropriate
101102 - Set default text colors on topmost container to cascade: `text-neutral-800 dark:text-neutral-200`
102103 - Use neutral color palette (not slate or gray)
104+ - **Markdown Styling**: Use Tailwind Typography plugin with `prose` classes for markdown content
105+ - Use `prose prose-neutral dark:prose-invert max-w-none` for assistant messages
106+ - The typography plugin is configured in `tailwind.config.js`
107+ - Custom syntax highlighting styles are in `app/highlight-theme.css` using `.prose` selectors
103108
104109 7. **Code Formatting**:
105110 - Use Prettier for code formatting: `npm run format` to format all files
@@ -111,7 +116,7 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
111116
112117 8. **Error Handling**:
113118 - Use `console.error` for errors
114- - Use `console.debug` for debug information
119+ - Use `lib/debug` for debug information
115120 - Return user-friendly error messages in API responses
116121 - Handle API errors gracefully with try/catch blocks
117122
@@ -237,10 +242,10 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
237242
238243 ### Component Structure
239244
240-- **Home** (`app/page.tsx`): Main page component that orchestrates the chat interface. Loads threads on mount but does not automatically select the latest thread - user must manually select a thread or create a new one.
245+- **Home** (`app/page.tsx`): Main page component that orchestrates the chat interface. Loads threads on mount but does not automatically select the latest thread - user must manually select a thread or create a new one. Messages are rendered with ReactMarkdown using Tailwind Typography prose classes for assistant messages.
241246 - **Sidebar** (`src/components/Sidebar.tsx`): Sidebar with thread selection, new thread button, and theme selector
242247 - **MessageInput** (`src/components/MessageInput.tsx`): Input form for sending messages with keyboard history navigation (ArrowUp/ArrowDown to cycle through previous user messages)
243-- **NoThreadSelected** (`src/components/NoThreadSelected.tsx`): Welcome screen displayed when no thread is selected, shows PAT introduction, current time (updates every second), and thread count
248+- **NoThreadSelected** (`src/components/NoThreadSelected.tsx`): Welcome screen displayed when no thread is selected, shows PAT introduction, current time (updates every second), and thread count. Uses ReactMarkdown with Tailwind Typography prose classes.
244249 - **useTheme** (`src/hooks/useTheme.ts`): Custom hook managing theme state (device/dark/light) with localStorage persistence and automatic device preference detection
245250
246251 ### Type Definitions
@@ -282,4 +287,4 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
282287 - **DO** maintain existing code style and patterns
283288 - **DO** use existing utility functions from `src/lib/`
284289 - **DO** follow the App Router conventions for Next.js 16
285-- **DO** keep this file up to date as changes are made in the code
290+- **DO** ALWAY Skeep this file up to date as changes are made in the code
app/globals.css+0−68
@@ -1,71 +1,3 @@
11 @tailwind base;
22 @tailwind components;
33 @tailwind utilities;
4-
5-.markdown-content {
6- @apply flex flex-col gap-6 text-neutral-800 dark:text-neutral-200;
7-}
8-
9-.markdown-content h1,
10-.markdown-content h2,
11-.markdown-content h3,
12-.markdown-content h4,
13-.markdown-content h5,
14-.markdown-content h6 {
15- @apply font-bold;
16-}
17-
18-.markdown-content h1 {
19- @apply text-2xl;
20-}
21-
22-.markdown-content h2 {
23- @apply text-xl;
24-}
25-
26-.markdown-content h3 {
27- @apply text-lg;
28-}
29-
30-.markdown-content ul {
31- @apply list-disc;
32-}
33-
34-.markdown-content ol {
35- @apply list-decimal;
36-}
37-
38-.markdown-content ul,
39-.markdown-content ol {
40- @apply flex flex-col gap-0;
41-}
42-
43-.markdown-content li {
44- @apply ml-4;
45-}
46-
47-.markdown-content blockquote {
48- @apply pl-2 border-l-4 border-neutral-500 italic dark:border-neutral-400;
49-}
50-
51-.markdown-content a {
52- @apply text-green-700 underline dark:text-green-400;
53-}
54-
55-.markdown-content table {
56- @apply border-collapse border border-neutral-500 dark:border-neutral-400;
57-}
58-
59-.markdown-content th,
60-.markdown-content td {
61- @apply border border-neutral-500 dark:border-neutral-400;
62-}
63-
64-.markdown-content th {
65- @apply bg-neutral-400 font-bold dark:bg-neutral-800;
66-}
67-
68-/* Code block styling */
69-.markdown-content pre {
70- @apply overflow-x-auto;
71-}
app/highlight-theme.css+68−68
@@ -1,26 +1,26 @@
11 /* Custom highlight.js theme using Tailwind colors (neutral, green, orange, indigo) */
22
33 /* Reset code block inheritance */
4-.markdown-content pre,
5-.markdown-content pre code {
4+.prose pre,
5+.prose pre code {
66 color: inherit;
77 }
88
99 /* Inline code - no background */
10-.markdown-content code:not(pre code) {
10+.prose code:not(pre code) {
1111 color: inherit;
1212 background: transparent;
1313 }
1414
1515 /* Light mode - code blocks only */
16-.markdown-content pre {
16+.prose pre {
1717 background: #f5f5f4; /* neutral-100 */
1818 padding: 0.5rem;
1919 }
2020
21-.markdown-content .hljs,
22-.markdown-content pre code.hljs,
23-.markdown-content pre .hljs,
21+.prose .hljs,
22+.prose pre code.hljs,
23+.prose pre .hljs,
2424 pre code.hljs,
2525 pre .hljs,
2626 .hljs {
@@ -28,17 +28,17 @@ pre .hljs,
2828 color: #292524; /* neutral-800 */
2929 }
3030
31-.markdown-content .hljs-comment,
32-.markdown-content .hljs-quote,
31+.prose .hljs-comment,
32+.prose .hljs-quote,
3333 .hljs-comment,
3434 .hljs-quote {
3535 color: #78716c; /* neutral-500 */
3636 font-style: italic;
3737 }
3838
39-.markdown-content .hljs-keyword,
40-.markdown-content .hljs-selector-tag,
41-.markdown-content .hljs-subst,
39+.prose .hljs-keyword,
40+.prose .hljs-selector-tag,
41+.prose .hljs-subst,
4242 .hljs-keyword,
4343 .hljs-selector-tag,
4444 .hljs-subst {
@@ -46,11 +46,11 @@ pre .hljs,
4646 font-weight: 600;
4747 }
4848
49-.markdown-content .hljs-number,
50-.markdown-content .hljs-literal,
51-.markdown-content .hljs-variable,
52-.markdown-content .hljs-template-variable,
53-.markdown-content .hljs-tag .hljs-attr,
49+.prose .hljs-number,
50+.prose .hljs-literal,
51+.prose .hljs-variable,
52+.prose .hljs-template-variable,
53+.prose .hljs-tag .hljs-attr,
5454 .hljs-number,
5555 .hljs-literal,
5656 .hljs-variable,
@@ -59,16 +59,16 @@ pre .hljs,
5959 color: #ea580c; /* orange-600 */
6060 }
6161
62-.markdown-content .hljs-string,
63-.markdown-content .hljs-doctag,
62+.prose .hljs-string,
63+.prose .hljs-doctag,
6464 .hljs-string,
6565 .hljs-doctag {
6666 color: #c2410c; /* orange-700 */
6767 }
6868
69-.markdown-content .hljs-title,
70-.markdown-content .hljs-section,
71-.markdown-content .hljs-selector-id,
69+.prose .hljs-title,
70+.prose .hljs-section,
71+.prose .hljs-selector-id,
7272 .hljs-title,
7373 .hljs-section,
7474 .hljs-selector-id {
@@ -76,16 +76,16 @@ pre .hljs,
7676 font-weight: 600;
7777 }
7878
79-.markdown-content .hljs-type,
80-.markdown-content .hljs-class .hljs-title,
79+.prose .hljs-type,
80+.prose .hljs-class .hljs-title,
8181 .hljs-type,
8282 .hljs-class .hljs-title {
8383 color: #6366f1; /* indigo-500 */
8484 }
8585
86-.markdown-content .hljs-tag,
87-.markdown-content .hljs-name,
88-.markdown-content .hljs-attribute,
86+.prose .hljs-tag,
87+.prose .hljs-name,
88+.prose .hljs-attribute,
8989 .hljs-tag,
9090 .hljs-name,
9191 .hljs-attribute {
@@ -93,28 +93,28 @@ pre .hljs,
9393 font-weight: normal;
9494 }
9595
96-.markdown-content .hljs-regexp,
97-.markdown-content .hljs-link,
96+.prose .hljs-regexp,
97+.prose .hljs-link,
9898 .hljs-regexp,
9999 .hljs-link {
100100 color: #c2410c; /* orange-700 */
101101 }
102102
103-.markdown-content .hljs-symbol,
104-.markdown-content .hljs-bullet,
103+.prose .hljs-symbol,
104+.prose .hljs-bullet,
105105 .hljs-symbol,
106106 .hljs-bullet {
107107 color: #ea580c; /* orange-600 */
108108 }
109109
110-.markdown-content .hljs-built_in,
111-.markdown-content .hljs-builtin-name,
110+.prose .hljs-built_in,
111+.prose .hljs-builtin-name,
112112 .hljs-built_in,
113113 .hljs-builtin-name {
114114 color: #4f46e5; /* indigo-600 */
115115 }
116116
117-.markdown-content .hljs-meta,
117+.prose .hljs-meta,
118118 .hljs-meta {
119119 color: #78716c; /* neutral-500 */
120120 }
@@ -136,25 +136,25 @@ pre .hljs,
136136 }
137137
138138 /* Dark mode */
139-.dark .markdown-content pre,
140-.dark .markdown-content pre code {
139+.dark .prose pre,
140+.dark .prose pre code {
141141 color: inherit;
142142 }
143143
144144 /* Inline code - no background */
145-.dark .markdown-content code:not(pre code) {
145+.dark .prose code:not(pre code) {
146146 color: inherit;
147147 background: transparent;
148148 }
149149
150-.dark .markdown-content pre {
150+.dark .prose pre {
151151 background: #0c0a09; /* neutral-950 */
152152 padding: 0.5rem;
153153 }
154154
155-.dark .markdown-content .hljs,
156-.dark .markdown-content pre code.hljs,
157-.dark .markdown-content pre .hljs,
155+.dark .prose .hljs,
156+.dark .prose pre code.hljs,
157+.dark .prose pre .hljs,
158158 .dark pre code.hljs,
159159 .dark pre .hljs,
160160 .dark .hljs {
@@ -162,17 +162,17 @@ pre .hljs,
162162 color: #e7e5e4; /* neutral-200 */
163163 }
164164
165-.dark .markdown-content .hljs-comment,
166-.dark .markdown-content .hljs-quote,
165+.dark .prose .hljs-comment,
166+.dark .prose .hljs-quote,
167167 .dark .hljs-comment,
168168 .dark .hljs-quote {
169169 color: #a8a29e; /* neutral-400 */
170170 font-style: italic;
171171 }
172172
173-.dark .markdown-content .hljs-keyword,
174-.dark .markdown-content .hljs-selector-tag,
175-.dark .markdown-content .hljs-subst,
173+.dark .prose .hljs-keyword,
174+.dark .prose .hljs-selector-tag,
175+.dark .prose .hljs-subst,
176176 .dark .hljs-keyword,
177177 .dark .hljs-selector-tag,
178178 .dark .hljs-subst {
@@ -180,11 +180,11 @@ pre .hljs,
180180 font-weight: 600;
181181 }
182182
183-.dark .markdown-content .hljs-number,
184-.dark .markdown-content .hljs-literal,
185-.dark .markdown-content .hljs-variable,
186-.dark .markdown-content .hljs-template-variable,
187-.dark .markdown-content .hljs-tag .hljs-attr,
183+.dark .prose .hljs-number,
184+.dark .prose .hljs-literal,
185+.dark .prose .hljs-variable,
186+.dark .prose .hljs-template-variable,
187+.dark .prose .hljs-tag .hljs-attr,
188188 .dark .hljs-number,
189189 .dark .hljs-literal,
190190 .dark .hljs-variable,
@@ -193,16 +193,16 @@ pre .hljs,
193193 color: #fb923c; /* orange-400 */
194194 }
195195
196-.dark .markdown-content .hljs-string,
197-.dark .markdown-content .hljs-doctag,
196+.dark .prose .hljs-string,
197+.dark .prose .hljs-doctag,
198198 .dark .hljs-string,
199199 .dark .hljs-doctag {
200200 color: #fdba74; /* orange-300 */
201201 }
202202
203-.dark .markdown-content .hljs-title,
204-.dark .markdown-content .hljs-section,
205-.dark .markdown-content .hljs-selector-id,
203+.dark .prose .hljs-title,
204+.dark .prose .hljs-section,
205+.dark .prose .hljs-selector-id,
206206 .dark .hljs-title,
207207 .dark .hljs-section,
208208 .dark .hljs-selector-id {
@@ -210,16 +210,16 @@ pre .hljs,
210210 font-weight: 600;
211211 }
212212
213-.dark .markdown-content .hljs-type,
214-.dark .markdown-content .hljs-class .hljs-title,
213+.dark .prose .hljs-type,
214+.dark .prose .hljs-class .hljs-title,
215215 .dark .hljs-type,
216216 .dark .hljs-class .hljs-title {
217217 color: #a5b4fc; /* indigo-300 */
218218 }
219219
220-.dark .markdown-content .hljs-tag,
221-.dark .markdown-content .hljs-name,
222-.dark .markdown-content .hljs-attribute,
220+.dark .prose .hljs-tag,
221+.dark .prose .hljs-name,
222+.dark .prose .hljs-attribute,
223223 .dark .hljs-tag,
224224 .dark .hljs-name,
225225 .dark .hljs-attribute {
@@ -227,28 +227,28 @@ pre .hljs,
227227 font-weight: normal;
228228 }
229229
230-.dark .markdown-content .hljs-regexp,
231-.dark .markdown-content .hljs-link,
230+.dark .prose .hljs-regexp,
231+.dark .prose .hljs-link,
232232 .dark .hljs-regexp,
233233 .dark .hljs-link {
234234 color: #fdba74; /* orange-300 */
235235 }
236236
237-.dark .markdown-content .hljs-symbol,
238-.dark .markdown-content .hljs-bullet,
237+.dark .prose .hljs-symbol,
238+.dark .prose .hljs-bullet,
239239 .dark .hljs-symbol,
240240 .dark .hljs-bullet {
241241 color: #fb923c; /* orange-400 */
242242 }
243243
244-.dark .markdown-content .hljs-built_in,
245-.dark .markdown-content .hljs-builtin-name,
244+.dark .prose .hljs-built_in,
245+.dark .prose .hljs-builtin-name,
246246 .dark .hljs-built_in,
247247 .dark .hljs-builtin-name {
248248 color: #818cf8; /* indigo-400 */
249249 }
250250
251-.dark .markdown-content .hljs-meta,
251+.dark .prose .hljs-meta,
252252 .dark .hljs-meta {
253253 color: #a8a29e; /* neutral-400 */
254254 }
app/page.tsx+16−14
@@ -37,19 +37,21 @@ export default function Home() {
3737 loadThreads();
3838 }, []);
3939
40+ useEffect(() => {
41+ // Scroll to top when a thread is selected
42+ if (currentThreadId !== null && messagesContainerRef.current) {
43+ messagesContainerRef.current.scrollTop = 0;
44+ }
45+ }, [currentThreadId]);
46+
4047 useEffect(() => {
4148 // Scroll to the start of the newly added message
4249 if (messages.length > prevMessagesLengthRef.current) {
4350 const newMessage = messages[messages.length - 1];
44- // Use requestAnimationFrame to ensure DOM has updated
45- requestAnimationFrame(() => {
46- const messageElement = messageRefs.current.get(newMessage.id);
47- if (messageElement && messagesContainerRef.current) {
48- const container = messagesContainerRef.current;
49- const messageTop = messageElement.offsetTop;
50- container.scrollTop = messageTop;
51- }
52- });
51+ const messageElement = messageRefs.current.get(newMessage.id);
52+ if (messageElement) {
53+ messageElement.scrollIntoView({ block: "start", behavior: "instant" });
54+ }
5355 prevMessagesLengthRef.current = messages.length;
5456 }
5557 }, [messages]);
@@ -181,7 +183,7 @@ export default function Home() {
181183 ref={messagesContainerRef}
182184 className="text-sm p-4 flex-1 overflow-y-auto overflow-x-hidden bg-neutral-100 dark:bg-neutral-950"
183185 >
184- <div className="flex min-h-full flex-col justify-end gap-8">
186+ <div className="flex min-h-full flex-col justify-end gap-8 max-w-4xl mx-auto">
185187 {currentThreadId === null ? (
186188 <NoThreadSelected threadCount={threads.length} />
187189 ) : (
@@ -195,13 +197,13 @@ export default function Home() {
195197 messageRefs.current.delete(msg.id);
196198 }
197199 }}
198- className="min-w-0"
200+ className="min-w-0 w-full"
199201 >
200202 <div
201- className={`markdown-content p-2 text-neutral-800 dark:text-neutral-200 ${
203+ className={`p-2 ${
202204 msg.role === "assistant"
203- ? "bg-neutral-200 dark:bg-neutral-900"
204- : "bg-neutral-300 dark:bg-neutral-800 text-right"
205+ ? "bg-neutral-200 dark:bg-neutral-900 prose prose-neutral dark:prose-invert max-w-none"
206+ : "bg-neutral-300 dark:bg-neutral-800 text-right w-1/2 min-w-64 ml-auto"
205207 }`}
206208 >
207209 {msg.role === "assistant" ? (
package-lock.json+26−0
@@ -8,6 +8,7 @@
88 "name": "personal-assistant-thing",
99 "version": "0.1.0",
1010 "dependencies": {
11+ "@tailwindcss/typography": "^0.5.19",
1112 "autoprefixer": "^10.4.17",
1213 "better-sqlite3": "^12.5.0",
1314 "drizzle-kit": "^0.31.8",
@@ -1740,6 +1741,31 @@
17401741 "tslib": "^2.8.0"
17411742 }
17421743 },
1744+ "node_modules/@tailwindcss/typography": {
1745+ "version": "0.5.19",
1746+ "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.19.tgz",
1747+ "integrity": "sha512-w31dd8HOx3k9vPtcQh5QHP9GwKcgbMp87j58qi6xgiBnFFtKEAgCWnDw4qUT8aHwkCp8bKvb/KGKWWHedP0AAg==",
1748+ "license": "MIT",
1749+ "dependencies": {
1750+ "postcss-selector-parser": "6.0.10"
1751+ },
1752+ "peerDependencies": {
1753+ "tailwindcss": ">=3.0.0 || insiders || >=4.0.0-alpha.20 || >=4.0.0-beta.1"
1754+ }
1755+ },
1756+ "node_modules/@tailwindcss/typography/node_modules/postcss-selector-parser": {
1757+ "version": "6.0.10",
1758+ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.0.10.tgz",
1759+ "integrity": "sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w==",
1760+ "license": "MIT",
1761+ "dependencies": {
1762+ "cssesc": "^3.0.0",
1763+ "util-deprecate": "^1.0.2"
1764+ },
1765+ "engines": {
1766+ "node": ">=4"
1767+ }
1768+ },
17431769 "node_modules/@tybys/wasm-util": {
17441770 "version": "0.10.1",
17451771 "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz",
package.json+1−0
@@ -14,6 +14,7 @@
1414 "db:studio": "drizzle-kit studio"
1515 },
1616 "dependencies": {
17+ "@tailwindcss/typography": "^0.5.19",
1718 "autoprefixer": "^10.4.17",
1819 "better-sqlite3": "^12.5.0",
1920 "drizzle-kit": "^0.31.8",
src/components/NoThreadSelected.tsx+2−2
@@ -29,8 +29,8 @@ export default function NoThreadSelected({ threadCount }: NoThreadSelectedProps)
2929 const timeDisplay = currentTime ? formatTime(currentTime) : "";
3030
3131 return (
32- <div className="min-w-0">
33- <div className="markdown-content p-1 bg-neutral-200 text-neutral-800 dark:bg-neutral-900 dark:text-neutral-200">
32+ <div className="min-w-0 max-w-4xl mx-auto">
33+ <div className="p-1 bg-neutral-200 dark:bg-neutral-900 prose prose-neutral dark:prose-invert">
3434 <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeHighlight]}>
3535 {`# Welcome to PAT 👋
3636
tailwind.config.js+1−1
@@ -4,5 +4,5 @@ module.exports = {
44 theme: {
55 extend: {},
66 },
7- plugins: [],
7+ plugins: [require("@tailwindcss/typography")],
88 };