-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Add basic markdown rendering for AI responses #21 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SushritaSingh
wants to merge
3
commits into
VaibhavCodeClub:master
Choose a base branch
from
SushritaSingh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,59 @@ | ||
{ | ||
"name": "term", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"preview": "vite preview", | ||
"test": "vitest run", | ||
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,md}\"", | ||
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,md}\"", | ||
"format:rust": "cd src-tauri && cargo fmt --all", | ||
"format:all": "npm run format && npm run format:rust", | ||
"prepare": "husky" | ||
}, | ||
"dependencies": { | ||
"eslint-define-config": "^2.1.0", | ||
"react": "^19.1.0", | ||
"react-dom": "^19.1.0" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.25.0", | ||
"@tauri-apps/api": "^2.5.0", | ||
"@tauri-apps/cli": "^2.5.0", | ||
"@testing-library/jest-dom": "^6.6.3", | ||
"@testing-library/react": "^16.3.0", | ||
"@testing-library/user-event": "^14.6.1", | ||
"@types/jest": "^29.5.14", | ||
"@types/react": "^19.1.2", | ||
"@types/react-dom": "^19.1.2", | ||
"@vitejs/plugin-react": "^4.4.1", | ||
"@vitest/coverage-v8": "3.1.4", | ||
"autoprefixer": "^10.4.21", | ||
"eslint": "^9.25.0", | ||
"eslint-plugin-react": "^7.34.3", | ||
"eslint-plugin-react-hooks": "^5.2.0", | ||
"eslint-plugin-react-refresh": "^0.4.19", | ||
"globals": "^16.0.0", | ||
"husky": "^9.0.11", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jsdom": "^26.1.0", | ||
"lint-staged": "^16.0.0", | ||
"postcss": "^8.5.3", | ||
"prettier": "^3.2.5", | ||
"tailwindcss": "^3.4.17", | ||
"ts-jest": "^29.3.4", | ||
"typescript": "~5.8.3", | ||
"typescript-eslint": "^8.30.1", | ||
"vite": "^6.3.5", | ||
"vitest": "^3.1.4" | ||
}, | ||
"packageManager": "[email protected]+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977" | ||
"name": "term", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"preview": "vite preview", | ||
"test": "vitest run", | ||
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,md}\"", | ||
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,md}\"", | ||
"format:rust": "cd src-tauri && cargo fmt --all", | ||
"format:all": "npm run format && npm run format:rust", | ||
"prepare": "husky" | ||
}, | ||
"dependencies": { | ||
"react": "^19.1.0", | ||
"react-dom": "^19.1.0", | ||
"react-markdown": "^8.0.7", | ||
"eslint-define-config": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.25.0", | ||
"@tauri-apps/api": "^2.5.0", | ||
"@tauri-apps/cli": "^2.5.0", | ||
"@testing-library/jest-dom": "^6.6.3", | ||
"@testing-library/react": "^16.3.0", | ||
"@testing-library/user-event": "^14.6.1", | ||
"@types/jest": "^29.5.14", | ||
"@types/react": "^19.1.2", | ||
"@types/react-dom": "^19.1.2", | ||
"@vitejs/plugin-react": "^4.4.1", | ||
"@vitest/coverage-v8": "3.1.4", | ||
"autoprefixer": "^10.4.21", | ||
"eslint": "^9.25.0", | ||
"eslint-plugin-react": "^7.34.3", | ||
"eslint-plugin-react-hooks": "^5.2.0", | ||
"eslint-plugin-react-refresh": "^0.4.19", | ||
"globals": "^16.0.0", | ||
"husky": "^9.0.11", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jsdom": "^26.1.0", | ||
"lint-staged": "^16.0.0", | ||
"postcss": "^8.5.6", | ||
"prettier": "^3.2.5", | ||
"tailwindcss": "^3.4.17", | ||
"ts-jest": "^29.3.4", | ||
"typescript": "~5.8.3", | ||
"typescript-eslint": "^8.30.1", | ||
"vite": "^6.3.5", | ||
"vitest": "^3.1.4" | ||
}, | ||
"packageManager": "[email protected]+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
import './App.css'; | ||
import Terminal from './components/Terminal'; | ||
import './App.css'; | ||
|
||
const exampleResponse = ` | ||
# AI Summary | ||
Here is some **bold text** and *italic text*. | ||
- Bullet Point 1 | ||
- Bullet Point 2 | ||
\`\`\`javascript | ||
console.log("Code block test"); | ||
\`\`\` | ||
⚠️ Error Message: | ||
\x1b[31merror\x1b[0m Something went wrong! | ||
`; | ||
|
||
const malformedResponse = ` | ||
### Unclosed *italic* | ||
**Bold without closing | ||
- List item | ||
`; | ||
|
||
function App() { | ||
return <Terminal />; | ||
return ( | ||
<div className="h-screen w-full bg-gray-950 text-white p-4 space-y-4"> | ||
{/* ✅ Use both to remove warning and test */} | ||
<Terminal aiResponse={exampleResponse} /> | ||
<Terminal aiResponse={malformedResponse} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn’t the actual terminal component - the real one is in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useState } from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
|
||
interface Message { | ||
type: 'command' | 'output' | 'error' | 'llm'; | ||
text: string; | ||
} | ||
|
||
interface TerminalProps { | ||
aiResponse?: string; // ✅ Optional prop | ||
} | ||
|
||
// ✅ Function to strip ANSI escape codes | ||
function stripAnsi(input: string): string { | ||
return input.replace(/\x1b\[[0-9;]*m/g, ''); | ||
} | ||
|
||
export default function Terminal({ aiResponse }: TerminalProps) { | ||
// ✅ Initialize state properly with lazy function to avoid re-runs | ||
const [messages] = useState<Message[]>(() => | ||
aiResponse | ||
? [{ type: 'llm', text: aiResponse }] | ||
: [ | ||
{ | ||
type: 'llm', | ||
text: ` | ||
# AI Response Example | ||
This is **bold**, _italic_, and a list: | ||
|
||
- First item | ||
- Second item | ||
|
||
Code block: | ||
\`\`\`javascript | ||
console.log("Hello Markdown!"); | ||
\`\`\` | ||
|
||
⚠️ Error Test: | ||
\x1b[31merror\x1b[0m Something went wrong! | ||
|
||
### Malformed Markdown Test | ||
**Bold without close | ||
_Unclosed italic | ||
`, | ||
}, | ||
] | ||
); | ||
|
||
return ( | ||
<div className="terminal-container bg-gray-900 text-white p-4 rounded-lg"> | ||
<div className="terminal-output space-y-2"> | ||
{messages.map((msg, idx) => ( | ||
<div key={idx} className={`terminal-line ${msg.type}`}> | ||
{msg.type === 'llm' ? ( | ||
<ReactMarkdown className="prose prose-invert max-w-none"> | ||
{stripAnsi(msg.text)} | ||
</ReactMarkdown> | ||
) : ( | ||
msg.text | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
<div className="terminal-input mt-2"> | ||
<input | ||
className="font-mono w-full bg-black text-white p-2 rounded" | ||
placeholder="Type a command..." | ||
disabled | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule term
added at
f40091
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you’ve swapped the actual terminal for a demo version here - this breaks the real app flow. we shouldn’t be hardcoding markdown props into ; markdown rendering needs to work inside the real terminal output from the AI responses.