Skip to content

Commit

Permalink
Merge pull request #111 from VishalPawar1010/#62-response-fromatting-…
Browse files Browse the repository at this point in the history
…using-remark-rehype

bug : fixed response formatting using rehype and ReactMarkdown
  • Loading branch information
shivaypiece authored Jul 8, 2024
2 parents e502021 + 1bd63dd commit 2114db4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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": {
"@testing-library/jest-dom": "^6.2.0",
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 @@ -99,7 +100,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 @@ -145,7 +146,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;
}
}

0 comments on commit 2114db4

Please sign in to comment.