Skip to content
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

bug : fixed response formatting using rehype and ReactMarkdown #111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"ts-node": "^10.9.1",
"jest-environment-jsdom": "^29.7.0"
"jest-environment-jsdom": "^29.7.0",
"rehype-sanitize": "6.0.0",
"react-markdown": "9.0.1"
},
"devDependencies": {
"@types/node": "^20.8.7",
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./Copilot.css";

import { applicationData } from "../../App";
import CopilotStreamController from '../../controllers/copilotStreamController';
import Markdown from '../ResponseFormat/Markdown';


let GlobalConversationID: string;
Expand Down Expand Up @@ -134,7 +135,7 @@ export function CopilotChat(): React.JSX.Element {
setMessage("")
setData("")
};

// for setting the initial copilot chat that takes place on page load.
useEffect(() => {
const getInitialChat = async () => {
Expand Down Expand Up @@ -180,7 +181,7 @@ export function CopilotChat(): React.JSX.Element {
</div>
<div className="messages">
<div>
<p>{message}</p>
<Markdown message={message} />
</div>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions src/app/components/ResponseFormat/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import ReactMarkdown from 'react-markdown';
import rehypeSanitize from 'rehype-sanitize';

interface MarkdownProps {
message: string;
}

const Markdown: React.FC<MarkdownProps> = ({ message }) => {
return (
<ReactMarkdown rehypePlugins={[rehypeSanitize]}>
{message}
</ReactMarkdown>
);
};

export default Markdown;
6 changes: 6 additions & 0 deletions src/app/components/ResponseFormat/rehypeSanitize.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'rehype-sanitize' {
import { Plugin } from 'unified';

const rehypeSanitize: Plugin;
export default rehypeSanitize;
}
51 changes: 47 additions & 4 deletions src/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ html {
}

.snippets-heading {
color: white;
font-weight: normal;
margin: 5px;
}

.snippets-heading-2 {
color: white;
font-weight: normal;
}

Expand Down Expand Up @@ -138,7 +136,6 @@ html {
cursor: pointer;
font-size: 12px;
}

.snippets-grid {
overflow-y: scroll;
min-width: 700px;
Expand All @@ -148,6 +145,8 @@ html {
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 5px;
background-color: #0e1111; /* Dark background color */
color: black; /* Text color */
}

.snippet-item {
Expand All @@ -160,7 +159,7 @@ html {
display: flex;
flex-direction: row;
justify-content: space-between;
/* background-color: white; */
background-color: white; /* Light background color */
cursor: pointer; /* Add cursor style to indicate clickability */
}

Expand All @@ -182,3 +181,47 @@ html {
box-shadow: -4px 4px 5px rgba(0, 0, 0, 0.2);
margin-top: 20px;
}


/* Common styles for the response formatting body */
body {
--bg-color: #000000; /* Pure black background */
--text-color: #e0e0e0; /* Light text color */
background-color: var(--bg-color);
color: var(--text-color);
}

code {
--code-bg-color: #000000; /* Pure black code block background */
--code-text-color: #ffffff; /* Pure white code text color */
background-color: var(--code-bg-color);
color: var(--code-text-color);
padding: 0.2em 0.4em;
border-radius: 3px;
font-family: 'Courier New', Courier, monospace;
}

/* Ensuring the styles for both light and dark modes */
@media (prefers-color-scheme: light) {
body {
--bg-color: #000000;
--text-color: #e0e0e0;
}

code {
--code-bg-color: #000000;
--code-text-color: #ffffff;
}
}

@media (prefers-color-scheme: dark) {
body {
--bg-color: #000000;
--text-color: #e0e0e0;
}

code {
--code-bg-color: #000000;
--code-text-color: #ffffff;
}
}
Loading