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
merged 3 commits into from Mar 29, 2018

Conversation

Projects
None yet
2 participants
@takluyver
Member

takluyver commented Jan 11, 2018

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

takluyver added some commits Jan 11, 2018

@takluyver

This comment has been minimized.

Member

takluyver commented Jan 18, 2018

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

4 checks passed

codecov/patch 72.41% of diff hit (target 0%)
Details
codecov/project 67.23% (+<.01%) compared to 7d533c3
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment