diff --git a/plugin/types.go b/plugin/types.go index 03aebc1..69ae990 100644 --- a/plugin/types.go +++ b/plugin/types.go @@ -47,20 +47,20 @@ type AIAction struct { // MasterPageBlock defines a block to add to a master page during provisioning. type MasterPageBlock struct { - BlockKey string - Title string - Content map[string]any - HtmlContent string - Slot string - SortOrder int32 + BlockKey string `json:"block_key"` + Title string `json:"title"` + Content map[string]any `json:"content"` + HtmlContent *string `json:"html_content"` + Slot string `json:"slot"` + SortOrder int32 `json:"sort_order"` } // MasterPageDefinition defines a default master page that a plugin provisions. type MasterPageDefinition struct { - Key string - Title string - PageTemplates []string - Blocks []MasterPageBlock + Key string `json:"key"` + Title string `json:"title"` + PageTemplates []string `json:"page_templates"` + Blocks []MasterPageBlock `json:"blocks"` } // Plugin status constants. diff --git a/render/blocknote.go b/render/blocknote.go index 84f7652..5e6df56 100644 --- a/render/blocknote.go +++ b/render/blocknote.go @@ -16,7 +16,7 @@ func BlockNoteToHTML(doc map[string]any) string { return renderBlocks(blocks) } -func renderBlocks(blocks []any) string { +func renderBlocks(blocks []map[string]any) string { var sb strings.Builder var currentListType string var listItems []map[string]any @@ -47,11 +47,7 @@ func renderBlocks(blocks []any) string { currentListType = "" } - for _, block := range blocks { - blockMap, ok := block.(map[string]any) - if !ok { - continue - } + for _, blockMap := range blocks { blockType, _ := blockMap["type"].(string) if blockType == "bulletListItem" || blockType == "numberedListItem" { @@ -71,36 +67,40 @@ func renderBlocks(blocks []any) string { return sb.String() } -func inlineContentFromRaw(raw any) []any { +func inlineContentFromRaw(raw any) []map[string]any { switch v := raw.(type) { case []any: - return v - case []map[string]any: - items := make([]any, 0, len(v)) + items := make([]map[string]any, 0, len(v)) for _, item := range v { - items = append(items, item) + if m, ok := item.(map[string]any); ok { + items = append(items, m) + } } return items + case []map[string]any: + return v case string: if v == "" { return nil } - return []any{map[string]any{"type": "text", "text": v}} + return []map[string]any{{"type": "text", "text": v}} default: return nil } } -func blocksFromRaw(raw any) []any { +func blocksFromRaw(raw any) []map[string]any { switch v := raw.(type) { case []any: - return v - case []map[string]any: - items := make([]any, 0, len(v)) + items := make([]map[string]any, 0, len(v)) for _, item := range v { - items = append(items, item) + if m, ok := item.(map[string]any); ok { + items = append(items, m) + } } return items + case []map[string]any: + return v default: return nil } @@ -265,14 +265,9 @@ func renderChildren(children any) string { return renderBlocks(blocks) } -func renderInlineContent(content []any) string { +func renderInlineContent(content []map[string]any) string { var sb strings.Builder - for _, item := range content { - itemMap, ok := item.(map[string]any) - if !ok { - continue - } - + for _, itemMap := range content { itemType, _ := itemMap["type"].(string) text, _ := itemMap["text"].(string) styles, _ := itemMap["styles"].(map[string]any)