Skip to content

Commit

Permalink
fix markdown style
Browse files Browse the repository at this point in the history
  • Loading branch information
saifullah-talukder committed Jul 5, 2024
1 parent 8c5e7e8 commit c65d25f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
31 changes: 31 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"date-fns": "^3.6.0",
"dompurify": "^3.1.5",
"lodash": "^4.17.21",
"markdown": "^0.5.0",
"next": "^14.2.3",
"next-auth": "^5.0.0-beta.19",
"next-themes": "^0.3.0",
Expand Down
30 changes: 20 additions & 10 deletions frontend/src/components/search/search-response.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { HTMLAttributes } from 'react'
import { HTMLAttributes, OlHTMLAttributes } from 'react'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import { twMerge } from 'tailwind-merge'

type SearchResponseProps = HTMLAttributes<HTMLDivElement> & {
response: string
}

const components = {
ol(props: OlHTMLAttributes<HTMLOListElement>) {
return (
<ol className="list-decimal pl-4" start={props.start}>
{props.children}
</ol>
)
},
ul(props: HTMLAttributes<HTMLUListElement>) {
return <ul className="list-disc pl-8">{props.children}</ul>
},
h3(props: HTMLAttributes<HTMLHeadingElement>) {
return <h3 className="font-bold text-lg">{props.children}</h3>
},
}

export default function SearchResponse(props: SearchResponseProps) {
return (
<div className={twMerge('flex flex-col gap-y-2', props.className)}>
{props.response.split('\\n').map((paragraph, index) => (
<div
key={`response-paragraph-${index}`}
//style={{ animation: `fade-in ${Math.min(1 + index * 0.5, 5)}s` }}
>
<Markdown className="text-sm text-white/80" remarkPlugins={[remarkGfm]}>
{paragraph}
</Markdown>
</div>
<Markdown key={`response-paragraph-${index}`} className="text-base text-white/80" components={components}>
{paragraph.replaceAll(' -', ' -')}
</Markdown>
))}
</div>
)
Expand Down

0 comments on commit c65d25f

Please sign in to comment.