jsvine / notebookjs

Render Jupyter/IPython notebooks on the fly, in the browser. (Or on the command line, if you'd like.)
MIT License
274 stars 48 forks source link

Rendering fails if metadata does not exist #21

Closed dereklieu closed 5 years ago

dereklieu commented 5 years ago

First: very cool library!

I've found that this line throws an exception when the metadata object does not exist. Since metadata properties are all optional, I imagine there are other instances of notebooks in the wild that don't have this property set to an empty {}.

Might be good to check that metadata is accessible to guard against throwing the exception in these cases.

Thanks!

jsvine commented 5 years ago

Thanks for flagging! Can you share a minimal notebook that raises this exception?

dereklieu commented 5 years ago

I've pasted such a file below. Using your preview site, the file will not generate anything as-is. If I add metadata: {} to the root object then it generates the heading as it should.

I don't know if it's common for most notebook authoring programs not to include at least an empty metadata object, but I'm working with some here that don't so it's certainly possible!

{
  "cells": [
    {
      "level": 1,
      "source": [
        "Demo of mpld3 (Updated!)"
      ],
      "metadata": {},
      "cell_type": "heading"
    }
  ]
}
jsvine commented 5 years ago

Thanks! Fixed in v0.4.2, now available on master and on npm.