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
Custom mime type for improved syntax highlighting of code when using outputs from IPython.display.Code #13795
Comments
Her'es the proposed change to the Just add a new mime type (that should not impact any existing code nor output of Jupyter Lab/Jupyter Notebook or others) def _repr_mimebundle_(self, **kwargs):
mime = "text/x-" + self.language
data = {mime:self.data}
return data |
I personally think that this is a good idea. This would fix #11747. |
Would this roughly double the size of jupyter kernel messages? Can this be changed in (how many?) other jupyter notebook/lab implementations? |
I bleieve this would be a 100% backward compatible change. This can even be implemented in a separate package for the time being and brought in IPython later. |
Today when users execute code to generate output with syntax highlighting, the output is HTML which contains highlighted using pygments lexer.
This looks great, however with multiple front ends have support for themes and different styles for highlithing the code, I was wondering whether it would be possible to generate a custom mime type that would return the raw code in with the mime type
text/x-<language>
.This way the front ends, such as Jupyter Lab, VS Code, and others would then have the option to pick these strings and perform the necessary syntax highlithing instead, optionally overriding the highlithing performed by the kernel.
I personally believe this would be benficial to Jupyter Lab as well, as they too support custom mime type renderers and could render code better in different themes.
Note: Today VS Code automatically supports mime syntax highlighting of output mime types of type
text/x-<language id>
I'm curious whether such a proposed change to the existing
IPyhton.display.Code
would be acceptable.Note: To be clear, what I'm suggestting is returning an additional mime type of
text/x-<language id>
along with the todays mime types oftext/html, text/latex, text/plain
See below screenshot
text/x-python
(similar mime types fromCode
)As you can see the output ends up being highlighted in VS Code with support for themes.
More information on the support for
text/x-<language id>
in VS Code can be found here https://code.visualstudio.com/api/extension-guides/notebook#rich-outputThe text was updated successfully, but these errors were encountered: