Possible to render a MarkdownCell inside a Widget (not a notebook)? (Extension)


I’m writing an extension that will be rendering some markdown that’s saved in a json file inside a larger Widget.

I started implementing this using Marked etc. however, I realised I may be re-inventing the wheel and thought I could use a MarkdownCell instead.

Unfortunately I’m completely stumped as to how to create and render a MarkdownCell outside of a notebook, or if this is even possible… I feel like it should be!

Where I’m currently stuck is that in order to create a MarkdownCell object I need to pass it a whole bunch of arguments as part of IMarkdownCellModel a lot of which I think are usually sorted by the notebook.

Any help of advice greatly appreciated.


What about the method used here?

Hi fomightez,

Thanks for the suggestion.

Unfortunately I’m trying to develop a Jupyter Lab extension and as such the solution needs to be implemented in TypeScript as part of that, rather than a pure Python solution.


Okay. That makes sense. I saw ‘widget’ and was thinking of the widgets for Voila apps.

If you just need to render markdown (i.e., if you don’t need editing, etc.), then perhaps you can just get the system markdown renderer from the rendering registry and use that to render to a node? In other words, you can just use the few lines from the markdown cell that actually does the rendering: https://github.com/jupyterlab/jupyterlab/blob/16fed812bcbd78a47827ffe6f57b5c0cabd2592d/packages/cells/src/widget.ts#L1494-L1500