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

Font information in lab template overriden by user stylesheet #1790

Closed
dakoop opened this issue Jun 8, 2022 · 1 comment · Fixed by #1793
Closed

Font information in lab template overriden by user stylesheet #1790

dakoop opened this issue Jun 8, 2022 · 1 comment · Fixed by #1793

Comments

@dakoop
Copy link
Contributor

dakoop commented Jun 8, 2022

The pygments preprocessor generates a different DOM structure inside of code cells, and this means that properties like the font-family are not inherited by the text inside of the highlighted code. This means that the fonts designated by JupyterLab themes, for example:

  --jp-code-font-family-default: Menlo, Consolas, 'DejaVu Sans Mono', monospace;
  --jp-code-font-family: var(--jp-code-font-family-default);

are overridden to use just monospace instead. In index.css, we have the lines

.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
  /* Reset some styles that the rest of the page might have set */
  -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
  border-width: 0;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  margin: 0;
  white-space: pre;
  word-wrap: normal;
  line-height: inherit;
  color: inherit;
  z-index: 2;
  position: relative;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-variant-ligatures: contextual;
  font-variant-ligatures: contextual;
}

which in JupyterLab trigger the font settings for CodeMirror to be inherited in pre blocks. The .CodeMirror .highlight pre has no corresponding style which seems to mean the user stylesheet takes precedence on pre and reverts any Jupyter-specific font settings.

Suggested Fix

Add the following rule to share/templates/lab/index.html.j2 (note that this also changes the padding to match the settings in JupyterLab)

.CodeMirror.cm-s-jupyter .highlight pre {
  /* weird, but --jp-code-padding defined to be 5px but 4px horizontal padding 
     is hardcoded for pre.CodeMirror-line */
  padding: var(--jp-code-padding) 4px;

  -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
  border-width: 0;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  margin: 0;
  white-space: pre;
  word-wrap: normal;
  line-height: inherit;
  color: inherit;
  z-index: 2;
  position: relative;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-variant-ligatures: contextual;
  font-variant-ligatures: contextual;
}

and remove the following rules in share/templates/lab/index.html.j2

.highlight {
margin: 0.4em;
}

.CodeMirror pre {
margin: 0;
padding: 0;
}

Nbconvert version: 6.5.0

@dakoop
Copy link
Contributor Author

dakoop commented Jun 9, 2022

This also affects outputs as well. For that, add

.jp-RenderedText pre {
  line-height: var(--jp-code-line-height);
  font-family: var(--jp-code-font-family);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant