Add markdown rendering with syntax highlighting and copy buttons

- Implement markdown parser using marked with Shiki syntax highlighting
- Add CodeBlockInline component for tool call outputs with syntax highlighting
- Add Markdown component for assistant message text with code blocks
- Add ThemeProvider for light/dark mode support
- Add copy buttons to all code blocks (markdown and tool calls)
- Support 20+ languages: TypeScript, JavaScript, Python, Bash, JSON, HTML, CSS, C++, Java, C, C#, Rust, Go, PHP, Ruby, Swift, Kotlin, and more
- Auto-detect language from file extensions in tool call outputs
- Apply consistent styling for code blocks across the application
- Fix whitespace handling in markdown-rendered text
- Add language labels to all code blocks
This commit is contained in:
Shantur Rathore
2025-10-23 10:07:17 +01:00
parent 7cf0f9a179
commit b836086978
9 changed files with 1130 additions and 35 deletions

View File

@@ -195,10 +195,8 @@ body {
.message-text {
font-size: 14px;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
}
.message-text pre {
@@ -753,3 +751,281 @@ body {
font-style: italic;
margin-top: 4px;
}
.prose {
color: #1a1a1a;
}
.prose code {
background-color: #f1f5f9;
color: #1e293b;
padding: 2px 6px;
border-radius: 4px;
font-size: 0.9em;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
.prose pre {
background-color: transparent;
padding: 0;
margin: 0;
overflow: visible;
}
.prose pre code {
background: transparent;
padding: 0;
border-radius: 0;
font-size: 0.875em;
}
.prose a {
color: #0066ff;
text-decoration: none;
}
.prose a:hover {
text-decoration: underline;
}
.prose blockquote {
border-left: 4px solid #e0e0e0;
padding-left: 16px;
font-style: italic;
color: #666;
margin: 12px 0;
}
.prose ul,
.prose ol {
margin: 8px 0;
padding-left: 24px;
}
.prose ul {
list-style-type: disc;
}
.prose ol {
list-style-type: decimal;
}
.prose li {
margin: 4px 0;
}
.prose h1 {
font-size: 1.5em;
font-weight: 700;
margin: 16px 0 12px 0;
line-height: 1.3;
}
.prose h2 {
font-size: 1.25em;
font-weight: 700;
margin: 14px 0 10px 0;
line-height: 1.3;
}
.prose h3 {
font-size: 1.1em;
font-weight: 600;
margin: 12px 0 8px 0;
line-height: 1.3;
}
.prose table {
border-collapse: collapse;
width: 100%;
margin: 12px 0;
font-size: 0.9em;
}
.prose th {
border: 1px solid #e0e0e0;
padding: 8px 12px;
background-color: #f5f5f5;
font-weight: 600;
text-align: left;
}
.prose td {
border: 1px solid #e0e0e0;
padding: 8px 12px;
}
.prose p {
margin: 8px 0;
}
.prose hr {
border: none;
border-top: 1px solid #e0e0e0;
margin: 16px 0;
}
[data-theme="dark"] .prose {
color: #e0e0e0;
}
[data-theme="dark"] .prose code {
background-color: #2a2a2a;
color: #e0e0e0;
}
[data-theme="dark"] .prose a {
color: #0080ff;
}
[data-theme="dark"] .prose blockquote {
border-left-color: #3a3a3a;
color: #999;
}
[data-theme="dark"] .prose th {
border-color: #3a3a3a;
background-color: #2a2a2a;
}
[data-theme="dark"] .prose td {
border-color: #3a3a3a;
}
[data-theme="dark"] .prose hr {
border-top-color: #3a3a3a;
}
.markdown-code-block {
position: relative;
margin: 12px 0;
border-radius: 6px;
overflow: hidden;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
}
[data-theme="dark"] .markdown-code-block {
background-color: #1a1a1a;
border-color: #3a3a3a;
}
.code-block-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background-color: #f1f5f9;
border-bottom: 1px solid #e0e0e0;
}
[data-theme="dark"] .code-block-header {
background-color: #2a2a2a;
border-bottom-color: #3a3a3a;
}
.code-block-language {
font-size: 12px;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
color: #666;
font-weight: 500;
text-transform: uppercase;
}
[data-theme="dark"] .code-block-language {
color: #999;
}
.code-block-copy {
display: flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
font-size: 12px;
background-color: transparent;
border: 1px solid #e0e0e0;
border-radius: 4px;
cursor: pointer;
color: #666;
transition: all 150ms ease;
}
[data-theme="dark"] .code-block-copy {
border-color: #3a3a3a;
color: #999;
}
.code-block-copy:hover {
background-color: #e0e0e0;
border-color: #ccc;
}
[data-theme="dark"] .code-block-copy:hover {
background-color: #3a3a3a;
border-color: #4a4a4a;
}
.code-block-copy .copy-icon {
width: 14px;
height: 14px;
}
.code-block-copy .copy-text {
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
.markdown-code-block pre {
margin: 0 !important;
padding: 12px !important;
overflow-x: auto;
background-color: transparent !important;
}
.markdown-code-block code {
background: transparent !important;
padding: 0 !important;
font-size: 13px !important;
line-height: 1.6;
}
.code-block-inline {
position: relative;
margin: 8px 0;
border-radius: 6px;
overflow: hidden;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
}
[data-theme="dark"] .code-block-inline {
background-color: #1a1a1a;
border-color: #3a3a3a;
}
.code-block-inline .code-block-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 10px;
background-color: #f1f5f9;
border-bottom: 1px solid #e0e0e0;
}
[data-theme="dark"] .code-block-inline .code-block-header {
background-color: #2a2a2a;
border-bottom-color: #3a3a3a;
}
.code-block-inline pre {
margin: 0 !important;
padding: 10px !important;
overflow-x: auto;
background-color: transparent !important;
}
.code-block-inline code {
background: transparent !important;
padding: 0 !important;
font-size: 12px !important;
line-height: 1.5;
}