Skip to content

Commit

Permalink
Fix rendering of code blocks in JupyterLab>= 4.3.0 (#111)
Browse files Browse the repository at this point in the history
* fix rendering of code blocks in JupyterLab >=4.3.0

Co-authored-by: david qiu <[email protected]>

* lint

---------

Co-authored-by: david qiu <[email protected]>
  • Loading branch information
brichet and dlqqq authored Dec 9, 2024
1 parent d4e6e5f commit a12fa00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/jupyter-chat/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export function Chat(props: Chat.IOptions): JSX.Element {
return (
<JlThemeProvider themeManager={props.themeManager ?? null}>
<Box
// Add .jp-ThemedContainer for CSS compatibility in both JL <4.3.0 and >=4.3.0.
// See: https://jupyterlab.readthedocs.io/en/latest/extension/extension_migration.html#css-styling
className="jp-ThemedContainer"
// root box should not include padding as it offsets the vertical
// scrollbar to the left
sx={{
Expand Down
16 changes: 12 additions & 4 deletions packages/jupyter-chat/style/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@
position: relative;
}

.jp-chat-rendermime-markdown .jp-RenderedHTMLCommon {
/*
*
* Selectors must be nested in `.jp-ThemedContainer` to have a higher
* specificity than selectors in rules provided by JupyterLab.
*
* See: https://jupyterlab.readthedocs.io/en/latest/extension/extension_migration.html#css-styling
* See also: https://github.com/jupyterlab/jupyter-ai/issues/1090
*/
.jp-ThemedContainer .jp-chat-rendermime-markdown .jp-RenderedHTMLCommon {
padding-right: 0;
}

.jp-chat-rendermime-markdown pre {
.jp-ThemedContainer .jp-chat-rendermime-markdown pre {
background-color: var(--jp-cell-editor-background);
overflow-x: auto;
white-space: pre;
Expand All @@ -31,13 +39,13 @@
border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
}

.jp-chat-rendermime-markdown pre > code {
.jp-ThemedContainer .jp-chat-rendermime-markdown pre > code {
background-color: inherit;
overflow-x: inherit;
white-space: inherit;
}

.jp-chat-rendermime-markdown mjx-container {
.jp-ThemedContainer .jp-chat-rendermime-markdown mjx-container {
font-size: 119%;
}

Expand Down

0 comments on commit a12fa00

Please sign in to comment.