| 1 | // Package notionmd maps a Notion page's block tree into Mapa's Markdown |
| 2 | // (Notion import spec §10, §11). It is pure: it reads a tree and writes |
| 3 | // a body, and imports markup so it can check its own output (D9). It |
| 4 | // imports nothing that dials, and never the Notion module itself: the |
| 5 | // tree below is Mapa's own copy of the module's typed tree, converted |
| 6 | // in import_convert.go, so that the staged trees Mapa seals are in a |
| 7 | // format Mapa owns (gate I8). |
| 8 | // |
| 9 | // Everything in a Page except ids, types, times and flags is CONTENT. |
| 10 | package notionmd |
| 11 | |
| 12 | // Page is one Notion page as surveyed: what Write renders from. |
| 13 | type Page struct { |
| 14 | ID string `json:"id"` |
| 15 | Title []Run `json:"title,omitempty"` |
| 16 | // Parent is the Notion id of the page this one was reached from, or |
| 17 | // "" for a root or an orphan whose parent is not imported. |
| 18 | Parent string `json:"parent,omitempty"` |
| 19 | Created string `json:"created,omitempty"` |
| 20 | Edited string `json:"edited,omitempty"` |
| 21 | // Icon and Cover are the page's look as Notion gives it (columns and |
| 22 | // icons spec §6.1). The runner imports them before the page's write; |
| 23 | // the mapper writes nothing of them. Their keys are new: a tree |
| 24 | // staged before they were read decodes with none. |
| 25 | Icon *Look `json:"pageIcon,omitempty"` |
| 26 | Cover *Look `json:"pageCover,omitempty"` |
| 27 | // Seq is the page's place in survey order (§9.2). |
| 28 | Seq int `json:"seq"` |
| 29 | Blocks []Block `json:"blocks,omitempty"` |
| 30 | } |
| 31 | |
| 32 | // Look is a page's icon or cover: Type is Notion's (emoji, |
| 33 | // custom_emoji, file or external), Emoji an emoji icon's, URL the rest's. |
| 34 | type Look struct { |
| 35 | Type string `json:"type"` |
| 36 | Emoji string `json:"emoji,omitempty"` |
| 37 | URL string `json:"url,omitempty"` |
| 38 | } |
| 39 | |
| 40 | // Block is one block and its children. |
| 41 | type Block struct { |
| 42 | ID string `json:"id"` |
| 43 | Type string `json:"type"` |
| 44 | Edited string `json:"edited,omitempty"` |
| 45 | // Known is false for a type the module could not decode; Type still |
| 46 | // names it. Unsupported is Notion's name for an "unsupported" block. |
| 47 | Known bool `json:"known,omitempty"` |
| 48 | Unsupported string `json:"unsupported,omitempty"` |
| 49 | |
| 50 | Text []Run `json:"text,omitempty"` |
| 51 | Caption []Run `json:"caption,omitempty"` |
| 52 | Checked bool `json:"checked,omitempty"` |
| 53 | Toggleable bool `json:"toggleable,omitempty"` |
| 54 | Language string `json:"language,omitempty"` |
| 55 | // WidthRatio is a column's share of its column_list, when Notion |
| 56 | // gives one (columns and icons spec §6.2): not imported, counted. |
| 57 | WidthRatio float64 `json:"width,omitempty"` |
| 58 | // Color is the block's colour, which the subset cannot say: counted. |
| 59 | Color string `json:"color,omitempty"` |
| 60 | // Emoji is a callout's icon when it is an emoji; IconType names any |
| 61 | // other kind of icon, which is counted. |
| 62 | Emoji string `json:"emoji,omitempty"` |
| 63 | IconType string `json:"iconType,omitempty"` |
| 64 | // Title is a child_page's or child_database's; a meeting_notes'. |
| 65 | Title string `json:"title,omitempty"` |
| 66 | File *File `json:"file,omitempty"` |
| 67 | URL string `json:"url,omitempty"` |
| 68 | Expression string `json:"expression,omitempty"` |
| 69 | Table *Table `json:"table,omitempty"` |
| 70 | Cells [][]Run `json:"cells,omitempty"` |
| 71 | // SyncedFrom is a synced copy's original. OriginalUnshared marks a |
| 72 | // copy whose children could not be read from it or its original. |
| 73 | SyncedFrom string `json:"syncedFrom,omitempty"` |
| 74 | OriginalUnshared bool `json:"originalUnshared,omitempty"` |
| 75 | LinkTo *Target `json:"linkTo,omitempty"` |
| 76 | Children []Block `json:"children,omitempty"` |
| 77 | } |
| 78 | |
| 79 | // Run is one rich text run. |
| 80 | type Run struct { |
| 81 | // Type is text, mention or equation. |
| 82 | Type string `json:"type"` |
| 83 | Text string `json:"text"` |
| 84 | // Href is Notion's href for the run; Link a text run's own link. |
| 85 | Href string `json:"href,omitempty"` |
| 86 | Link string `json:"link,omitempty"` |
| 87 | Bold bool `json:"b,omitempty"` |
| 88 | Italic bool `json:"i,omitempty"` |
| 89 | Strike bool `json:"s,omitempty"` |
| 90 | Underline bool `json:"u,omitempty"` |
| 91 | Code bool `json:"c,omitempty"` |
| 92 | Color string `json:"color,omitempty"` |
| 93 | Mention *Mention `json:"mention,omitempty"` |
| 94 | Expression string `json:"expression,omitempty"` |
| 95 | } |
| 96 | |
| 97 | // Mention is a typed mention: page, database, date, user, link_preview, |
| 98 | // link_mention, template_mention, custom_emoji, or a type Notion adds. |
| 99 | type Mention struct { |
| 100 | Type string `json:"type"` |
| 101 | ID string `json:"id,omitempty"` |
| 102 | Name string `json:"name,omitempty"` |
| 103 | Start string `json:"start,omitempty"` |
| 104 | End string `json:"end,omitempty"` |
| 105 | TimeZone string `json:"zone,omitempty"` |
| 106 | URL string `json:"url,omitempty"` |
| 107 | } |
| 108 | |
| 109 | // File is a file block's source. Type is file (Notion-hosted, its URL |
| 110 | // signed and expiring), external, or file_upload. |
| 111 | type File struct { |
| 112 | Type string `json:"type"` |
| 113 | URL string `json:"url,omitempty"` |
| 114 | Name string `json:"name,omitempty"` |
| 115 | } |
| 116 | |
| 117 | // Table is a table's shape. |
| 118 | type Table struct { |
| 119 | Width int `json:"width"` |
| 120 | ColumnHeader bool `json:"columnHeader,omitempty"` |
| 121 | RowHeader bool `json:"rowHeader,omitempty"` |
| 122 | } |
| 123 | |
| 124 | // Target is a link_to_page's target: page or database, and its id. |
| 125 | type Target struct { |
| 126 | Type string `json:"type"` |
| 127 | ID string `json:"id"` |
| 128 | } |
| 129 | |