[IPython-dev] Notebook codemirror support for language not distributed with codemirror?

Tom Quarendon tom.quarendon at teamwpc.co.uk
Mon Nov 16 08:39:21 EST 2015

> You can drop a kernel.js next to your kernel.json  at installation 
> time, it should  describe an AMD module that define an `onload` method 
> that will be called when you switch to your kernel.

The thing it's just taken me a *very* long time to figure out is that because of the way that the kernel.js file is loaded, you can't use relative module IDs in require or define calls. So in my kernel.js file I naively had;

function(require) {
	return {
		onload: function() {

However it only works if you make it "mymode.js", and then if any require calls that "mymode.js" has also use ".js" suffixes on the filenames, a pain because I'm using TypeScript generated javascript. Doing it this way won't resolve "module IDs", and this is a function of the way that the kernel.js file is loaded (it's loaded as an explicit path with a leading /, so anything resolved relative to it also has a leading slash, and if you have a leading slash it bypasses the "module ID" path resolution bits in require.js).

Anyway. What I *finally* worked out is that if I write:
Instead (NO leading slash), it all works, and I don’t have to modify my code, this "kernel.js" file can do all the adaptation I need.

Anyway. In case anyone else has the same problem :-)

More information about the IPython-dev mailing list