Skip to content

Commit

Permalink
feat: support v1.0 and v2.0 notebooks
Browse files Browse the repository at this point in the history
Turns out, v1 and v2 only differ in how Jupyter interprets them,
not in the schema itself. We can use the same decoder we use
for v3.
  • Loading branch information
bevzzz committed Feb 26, 2024
1 parent 87c1543 commit c968444
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions decode/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ func TestDecodeBytes(t *testing.T) {
}`,
nCells: 3,
},
{
name: "v2.0",
json: `{
"nbformat": 2, "nbformat_minor": 0, "metadata": {}, "worksheets": [
{"cells": [
{"cell_type": "markdown", "metadata": {}, "source": []},
{"cell_type": "markdown", "metadata": {}, "source": []}
]},
{"cells": [
{"cell_type": "markdown", "metadata": {}, "source": []}
]}
]
}`,
nCells: 3,
},
{
name: "v1.0",
json: `{
"nbformat": 1, "nbformat_minor": 0, "metadata": {}, "worksheets": [
{"cells": [
{"cell_type": "markdown", "metadata": {}, "source": []},
{"cell_type": "markdown", "metadata": {}, "source": []}
]},
{"cells": [
{"cell_type": "markdown", "metadata": {}, "source": []}
]}
]
}`,
nCells: 3,
},
} {
t.Run(tt.name, func(t *testing.T) {
nb, err := decode.Bytes([]byte(tt.json))
Expand Down
4 changes: 3 additions & 1 deletion schema/v3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (

func init() {
decode.RegisterDecoder(schema.Version{Major: 3, Minor: 0}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 2, Minor: 0}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 1, Minor: 0}, new(decoder))
}

// decoder decodes cell contents and metadata for nbformat v3.0.
// decoder decodes cell contents and metadata for nbformat v3.0, v2.0, and v1.0.
type decoder struct{}

var _ decode.Decoder = (*decoder)(nil)
Expand Down

0 comments on commit c968444

Please sign in to comment.