Skip to content

Commit

Permalink
tweak font styles for code blocks in chat (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq authored May 6, 2023
1 parent 5ec8cab commit 76278de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/jupyter-ai/src/components/chat-code-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { CodeProps } from 'react-markdown/lib/ast-to-react';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { duotoneLight } from 'react-syntax-highlighter/dist/esm/styles/prism';
import { Box, Button } from '@mui/material';
import cx from 'clsx';

type ChatCodeViewProps = CodeProps;

Expand All @@ -13,13 +14,15 @@ type ChatCodeBlockProps = ChatCodeViewProps & {
language?: string;
};

const JPAI_CODE_CLASS = 'jp-ai-code';

function ChatCodeInline({
className,
children,
...props
}: ChatCodeInlineProps) {
return (
<code {...props} className={className}>
<code {...props} className={cx(JPAI_CODE_CLASS, className)}>
{children}
</code>
);
Expand Down Expand Up @@ -59,6 +62,7 @@ function ChatCodeBlock({ language, children, ...props }: ChatCodeBlockProps) {
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<SyntaxHighlighter
{...props}
className={cx(props.className, JPAI_CODE_CLASS)}
children={value}
style={duotoneLight}
language={language}
Expand Down
13 changes: 10 additions & 3 deletions packages/jupyter-ai/style/react-markdown.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.jp-RenderedHTMLCommon.jp-ai-react-markdown > pre {
margin: 0px;
margin: 0;
}

.jp-RenderedHTMLCommon.jp-ai-react-markdown {
padding: 0px;
}
padding: 0;
}

/* !important specifier required to override inline styles from Prism */
.jp-ai-code {
font-family: var(--jp-code-font-family) !important;
font-size: var(--jp-code-font-size) !important;
line-height: var(--jp-code-line-height) !important;
}

0 comments on commit 76278de

Please sign in to comment.