I wrote a loader for this. And there are tools to split cells for compiling. I wrote a tool to split up cells too and compile in order. Pretty easy, all the code is in notebooks.
My JavaScript version I just put a simple wrapper around my print-results call to check if it is in module mode or notebook mode.