vatlab / sos-notebook

Multi-language Jupyter Notebook
http://vatlab.github.io/SoS
BSD 3-Clause "New" or "Revised" License
176 stars 17 forks source link

Syntax highlighting for custom language modules #326

Closed sillymoi closed 3 years ago

sillymoi commented 3 years ago

Hi,

I'm trying out sos notebooks with multiple homegrown kernels supported by a single sos language plugin. All of the kernels are using the same input language (RDF turtle in this case), and I'd like to enable syntax highlighting in the cells. Following the discussion around C++, I added the codemirror mode to imports of sos-notebook, as well as to the modeMap and extMap in kernel.js. What I'm missing is how to tell sos which mode to use, I'm not sure if the problem is in my plugin, the mode definition in kernel.js... or something else.

Thanks for any pointers :)

BoPeng commented 3 years ago

Does this RDF Turtle kernel has a concept of "variable", namely, it is worthwhile to define a language module to pass variables around?

sillymoi commented 3 years ago

Not really, no... it's just a front to send HTTP requests with the given payload (alongside some decoration), similar to SPARQL modules - there are no variables in pythonic sense, but query results could be passed around in a similar way, I'm still not there yet.

At start, I defined the language module mainly to specify the color of the cells. Is there some other way you can suggest?

I made some changes recently, thought that adding this to language_info of the kernel itself would help sos set the mode correctly:

class MyKernel(Kernel):
    language_info = {'name': 'turtle',
                                 'codemirror_mode': 'turtle',
                                 'file_extension': '.ttl',
                                 'mimetype': 'text/turtle'}`
...

How does sos determine the mode?

BoPeng commented 3 years ago

Could you send me url for the kernel.

I want to use config file for this and solve the problem once for all.

sillymoi commented 3 years ago

I don't have it on github right now, will push and send the link later.

Den ons 18 aug. 2021 12:46Bo @.***> skrev:

Could you send me url for the kernel.

I want to use config file for this and solve the problem once for all.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vatlab/sos-notebook/issues/326#issuecomment-901011788, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA742A5KLHKSC6KYGPHPGX3T5OFOVANCNFSM5CKZ3CPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

BoPeng commented 3 years ago

@sillymoi Any update?

sillymoi commented 3 years ago

https://github.com/sillymoi/turtle-kernel try this one, enter whatever and the kernel will output a small turtle code example you can use to test formatting. 'plain' jupyter does the highlighting:

image

sos looks different:

image

note that i added turtle codemirror mode codemirror/mode/turtle/turtle to kernel.js imports (define[..]) in sos_notebook, and also ttl: "turtle" to extMap, turtle: "turtle" to modeMap.

BoPeng commented 3 years ago

Thanks. Could you push your changes as a PR so that I can try it?

sillymoi commented 3 years ago

there it is

BoPeng commented 3 years ago

@sillymoi I have fixed the issue. Please test it if you get some time. Basically, you will need to

  1. install the master branch of sos-notebook.
  2. Run python -m sos_notebook.install, due to some complications with most reent version of jupyter_client, you will need to use an async kernel manager for jupyter, I have the issue listed in the output of the install command
  3. Add "turtle": "turtle" to ~/.jupyter/nbconfig/notebook.json and start jupyter notebook