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

Add display class for syntax-highlighted code #10978

merged 3 commits into from Mar 29, 2018


Copy link

Preparing some workshop materials, I've found myself wanting a better way to display a separate code file in a notebook.

  • !cat doesn't highlight code, and it only works if cat is available.
  • %pycat displays code in the pager, not as regular output, and its highlighting is specific to Python code.

There are many ways this could be extended - to add more output formats, or to let the user pick a pygments style, for instance. But I think what's there probably meets the 80% use case.

@takluyver takluyver added this to the 6.3 milestone Jan 11, 2018
Copy link
Member Author

I did have another idea how to achieve this: send plain text with some metadata identifying the language, and let the frontend do the highlighting if it can: jupyter/nbconvert#363

That proposal is more elegant: it only sends the data once, it allows frontends to highlight in formats the kernel many not know about, and it works nicely for converting to formats like rst and markdown, which don't include highlighted code themselves, but may be rendered into a format which does.

However, this idea can be implemented in IPython and be useful immediately, whereas the other one requires changes to several different projects.

@takluyver takluyver merged commit b9e079f into ipython:master Mar 29, 2018
@takluyver takluyver deleted the display-code branch December 12, 2019 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants