diff --git a/examples/grpc-client/main.go b/examples/grpc-client/main.go index 130aa509d..98879fa8f 100644 --- a/examples/grpc-client/main.go +++ b/examples/grpc-client/main.go @@ -65,13 +65,14 @@ func run() error { client := parserv1.NewParserServiceClient(conn) resp, err := client.Deserialize(context.Background(), &parserv1.DeserializeRequest{ - Source: []byte(""), + Source: []byte("# Hello"), }) if err != nil { return err } _, _ = fmt.Println(resp.Notebook) + _, _ = fmt.Println(resp.Notebook.Cells[0].Metadata) return nil } diff --git a/internal/document/editor/cell.go b/internal/document/editor/cell.go index 3d1e994b1..98e27745a 100644 --- a/internal/document/editor/cell.go +++ b/internal/document/editor/cell.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "os" "strconv" "strings" @@ -150,13 +151,19 @@ func toCellsRec( astNode := block.Unwrap() metadata := make(map[string]string) - astMetadata := DumpToMap(astNode, source, astNode.Kind().String()) - jsonAstMetaData, err := json.Marshal(astMetadata) - if err != nil { - log.Fatalf("Error converting to JSON: %s", err) - } + _, includeAstMetadata := os.LookupEnv("RUNME_AST_METADATA") + + if includeAstMetadata { + astMetadata := DumpToMap(astNode, source, astNode.Kind().String()) + jsonAstMetaData, err := json.Marshal(astMetadata) + if err != nil { + log.Fatalf("Error converting to JSON: %s", err) + } - metadata["runme.dev/ast"] = string(jsonAstMetaData) + env := os.Environ() + fmt.Println(env) + metadata["runme.dev/ast"] = string(jsonAstMetaData) + } isListItem := node.Item() != nil && node.Item().Unwrap().Kind() == ast.KindListItem if childIdx == 0 && isListItem { diff --git a/internal/document/editor/editor_test.go b/internal/document/editor/editor_test.go index 2e86ab3ca..e1deb53c5 100644 --- a/internal/document/editor/editor_test.go +++ b/internal/document/editor/editor_test.go @@ -3,6 +3,7 @@ package editor import ( "bytes" "encoding/json" + "os" "testing" "github.com/stretchr/testify/assert" @@ -105,6 +106,7 @@ Paragraph 1 with a link [Link1](https://example.com 'Link Title 1') and a second #### Heading Level 4 ##### Heading Level 5 `) + os.Setenv("RUNME_AST_METADATA", "true") notebook, err := Deserialize(data) require.NoError(t, err) require.NotEmpty(t, notebook.Metadata) diff --git a/internal/document/editor/editorservice/service_test.go b/internal/document/editor/editorservice/service_test.go index a92a3ad19..e4a1a6c97 100644 --- a/internal/document/editor/editorservice/service_test.go +++ b/internal/document/editor/editorservice/service_test.go @@ -3,6 +3,7 @@ package editorservice import ( "context" "net" + "os" "testing" "github.com/stateful/runme/internal/document/editor" @@ -33,6 +34,8 @@ func Test_parserServiceServer(t *testing.T) { client := parserv1.NewParserServiceClient(conn) t.Run("Basic", func(t *testing.T) { + os.Setenv("RUNME_AST_METADATA", "true") + resp, err := client.Deserialize( context.Background(), &parserv1.DeserializeRequest{