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

Innovation time - Github markdown model card details code highlighting #1581

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"swagger-ui-react": "^5.17.14",
"swr": "^2.2.5",
"typescript": "5.5.3",
"uuid": "^10.0.0"
"uuid": "^10.0.0",
"react-syntax-highlighter": "15.5.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect there to be accompanying package-lock.json changes with installing a new package. Make sure those changes are also committed

},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.4",
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/common/MarkdownDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTheme } from '@mui/material/styles'
import Typography from '@mui/material/Typography'
import ReactMarkdown from 'markdown-to-jsx'
import { useMemo } from 'react'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'

export type MarkdownDisplayProps = {
children: string
Expand Down Expand Up @@ -99,6 +100,24 @@ export default function MarkdownDisplay({ children }: MarkdownDisplayProps) {
/>
),
},
code: {
component: ({ children, ...props }: any) => {
const language = props.className ? props.className.replace('lang-', '') : ''

return (
<Box
component='code'
sx={{
backgroundColor: theme.palette.grey[200],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a theme colour that works in both light and dark modes. A static colour will not work for both.

fontFamily: 'monospace',
}}
{...props}
>
{language ? <SyntaxHighlighter language={language}>{children}</SyntaxHighlighter> : children}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that all colours used by this package conform to accessibility contrast requirements for both light and dark mode themes.

</Box>
)
},
},
table: {
component: (props: any) => (
<div style={{ overflowX: 'auto' }}>
Expand All @@ -108,7 +127,7 @@ export default function MarkdownDisplay({ children }: MarkdownDisplayProps) {
},
},
}),
[theme.palette.container.main, theme.palette.markdownBorder.main],
[theme.palette.container.main, theme.palette.grey, theme.palette.markdownBorder.main],
)

return <ReactMarkdown options={options}>{children}</ReactMarkdown>
Expand Down
Loading