Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add support for cell magics to specify cell language type (for highlighting / interpreting) #10667
Comments
|
Hi @matthewwardrop, What you ask is a bit tough. The problem is that the frontend is not aware that |
|
If this feature is added, it should ideally be supported in the terminal too. |
It would technically be way easier to implement in the terminal than in the notebook. |
matthewwardrop commentedJun 17, 2017
•
edited
Greetings all,
Background
I've been working on a project called Omniduct (http://github.com/airbnb/omniduct), which among other things dynamically adds cell magics to the user IPython session that expose certain data sources in a convenient manner.
For example, if one is running multiple HiveServer2 instances somewhere, you can configure as appropriate various connection parameters, after which you can register cell magics associated with these services with base names of "hive1" and "hive2", for example. This then adds line and cell magics to the user session like
%hive1.descfor getting table descriptions/schemas and%%hive2(followed by SQL) for querying the database.Feature Request
At time of IPython magic registration, I would like to be able to specify the expected language/markup of the cell contents. This would allow appropriate highlighting of cell contents for any cell magic (and should probably default to no highlighting if not specified). Currently, as of PR #2216, there is support for highlighting cell contents, but this support is limited to several pre-defined languages that are hard-coded into the javascript itself. I am imagining code that looks something like this:
As a workaround, it looks like it might be possible to hack javascript into the user session using something like that shown in #7699, but this seems a little messy.
Is this something that is in-principle ruled out? Is this something that you would be interested in seeing contributions for?
Extra points
It would be even more amazing if you could optionally pass a callable object as the language, which gets evaluated at runtime based upon the cell contents. This will obviously be much more difficult, since it needs to bridge the kernel/js bridge and perhaps support non-Python languages. But I'm imagining this might look something like: