Skip to content

Commit

Permalink
fixes extra spaces when there is no metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso committed Nov 7, 2023
1 parent 17c42f1 commit 796a444
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/document/editor/editorservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ func (s *parserServiceServer) Serialize(_ context.Context, req *parserv1.Seriali
raw := req.Notebook.Metadata[frontMatterKey]

_, info := document.ParseFrontmatterWithIdentity(raw, false)
req.Notebook.Metadata[frontMatterKey] = info.GetRaw()
raw = info.GetRaw()
if raw == "" {
delete(req.Notebook.Metadata, frontMatterKey)
} else {
req.Notebook.Metadata[frontMatterKey] = raw
}
}

data, err := editor.Serialize(&editor.Notebook{
Expand Down
6 changes: 3 additions & 3 deletions internal/document/editor/editorservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Some content
})

t.Run("Frontmatter Identity RUNME_IDENTITY_UNSPECIFIED Empty", func(t *testing.T) {
content := ""
content := "# H1"

dResp, err := client.Deserialize(
context.Background(),
Expand All @@ -233,7 +233,7 @@ Some content
)

assert.NoError(t, err)
assert.Len(t, dResp.Notebook.Cells, 0)
assert.Len(t, dResp.Notebook.Cells, 1)
sResp, err := client.Serialize(
context.Background(),
&parserv1.SerializeRequest{
Expand All @@ -245,6 +245,6 @@ Some content
)

assert.NoError(t, err)
assert.Equal(t, "", string(sResp.Result))
assert.Equal(t, content, string(sResp.Result))
})
}

0 comments on commit 796a444

Please sign in to comment.