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

Missing syntax highlighting for the JSON viewer #6567

Closed
jtpio opened this issue Oct 13, 2022 · 15 comments · Fixed by #6678
Closed

Missing syntax highlighting for the JSON viewer #6567

jtpio opened this issue Oct 13, 2022 · 15 comments · Fixed by #6678
Labels
Milestone

Comments

@jtpio
Copy link
Member

jtpio commented Oct 13, 2022

As noticed in #6566 (comment), syntax highlighting is missing when opening JSON files with the JSON viewer:

image

@jtpio jtpio added the bug label Oct 13, 2022
@jtpio jtpio added this to the 7.0 milestone Oct 13, 2022
@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to issues that need triage label Oct 13, 2022
@jtpio jtpio removed the status:Needs Triage Applied to issues that need triage label Oct 13, 2022
@kostyafarber
Copy link
Contributor

This looks interesting. Any ideas on where to get started with this?

@kostyafarber
Copy link
Contributor

Can't seem to locate where this bug is originated. I can see some inline styles being generated in JupyterLab for the same viewer but don't know why they aren't doing the same in the notebook 🤔

@jtpio
Copy link
Member Author

jtpio commented Nov 14, 2022

Thanks @kostyafarber for looking into this.

Right I guess the first step would be to check if the styles are correctly added to the page, as there could be one missing in notebook compared to lab (haven't looked more into it since)

@kostyafarber
Copy link
Contributor

Can't seem to isolate why notebook is not applying the styles. I can see in JupyterLab style tags are produced with these ͼr styles in head but in notebook they are missing.

I can't find any reference to these in the code anywhere. They look like they are to do with CodeMirror but don't know how they are produced by it.

Screenshot 2022-11-18 at 22 03 19

@fcollonval
Copy link
Collaborator

@kostyafarber for CodeMirror 6, the theme uses CSS in JS (see documentation). That way is usually combined with auto-generated class name (as you are seeing). But they are never mentioned explicitly in the code (as they should never be used and can change without notice).

So if in notebook you can see the style applied have colored defined like var(--jp-mirror-editor-keyword-color). This means the JupyterLab CodeMirror theme is correctly applied by the JSON viewer. But those CSS properties are not define on the page - they should come from the theme package:

https://github.com/jupyterlab/jupyterlab/blob/9ee65ca27712b19cb8a7a2f4e99453ef1439a525/packages/theme-light-extension/style/variables.css#L335

@kostyafarber
Copy link
Contributor

@fcollonval okay, I can see these styles in the debug console on notebook.

image

I can even see the ͼ12 styles attached to the spans in the JSON (which are the styles that have colours applied to them in Lab), but there are no styles defined on them in notebook.

It looks like these styles are being extracted by this function here:

https://github.com/jupyterlab/jupyterlab/blob/3dadf14e4411c3af143f97d055b3309901216ad7/packages/json-extension/src/component.tsx#L37-L39

And being called here for example:

https://github.com/jupyterlab/jupyterlab/blob/3dadf14e4411c3af143f97d055b3309901216ad7/packages/json-extension/src/component.tsx#L82-L84

But these styles aren't being produced on notebook. Not sure how to map that to a missing css import on the page. Is there meant to be an extra css file defined somewhere here to enable this function to work properly in notebook?

https://github.com/jupyter/notebook/blob/main/packages/application/style/index.css

@fcollonval
Copy link
Collaborator

Ok I think I get what is happening - the CodeMirror theme rules are not added to the page because there are no CodeMirror editor.

@fcollonval
Copy link
Collaborator

What we should do is add the CodeMirror rules on the page for the JSON Renderer.

https://github.com/jupyterlab/jupyterlab/blob/42992295a40e030d7875ab063aa8ebb1ada3ca74/packages/json-extension/src/component.tsx#L38

You can do that by adding manually the style using style-mod:

StyleModule.mount(document, jupyterHighlightStyle.module)

@kostyafarber
Copy link
Contributor

kostyafarber commented Nov 21, 2022

Ah okay , as there is no CodeMirror Editor on the JSON Renderer. Thanks for the investigation @fcollonval

Should this PR be done in JupyterLab and then I can reference this issue there?

@fcollonval
Copy link
Collaborator

StyleModule is designed to add a style sheet only once. So I would suggest fixing it upstream.

@kostyafarber
Copy link
Contributor

Sorry if this is a silly question, but what do you mean by fixing it upstream?

@fcollonval
Copy link
Collaborator

Sorry fixing it in JupyterLab itself

@kostyafarber
Copy link
Contributor

All good! Thanks for the help 😄

@fcollonval
Copy link
Collaborator

fcollonval commented Nov 21, 2022

We usually refer to JupyterLab as the upstream of notebook as notebook v7 is a remix of JupyterLab plugins.

@kostyafarber
Copy link
Contributor

kostyafarber commented Nov 21, 2022

Ah okay. Thanks for that. Good to know the lingo.

I'll work on it and open a PR upstream and reference this issue.

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

Successfully merging a pull request may close this issue.

3 participants