| 1 | package notionmd |
| 2 | |
| 3 | // blockFixtures is one fixture per row of §10.1's table. |
| 4 | func blockFixtures() []fixture { |
| 5 | return append(textBlockFixtures(), containerFixtures()...) |
| 6 | } |
| 7 | |
| 8 | func textBlockFixtures() []fixture { |
| 9 | return []fixture{ |
| 10 | page("paragraph", para(txt("A paragraph.\nWith a line break.")), |
| 11 | para(txt("One.\n\n\nTwo, after blank lines.")), |
| 12 | with(para(txt("Indented below:")), para(txt("An indented one.")))), |
| 13 | page("headings", blk("heading_1", txt("One")), |
| 14 | blk("heading_2", txt("Two")), blk("heading_3", txt("Three")), |
| 15 | blk("heading_4", txt("Four")), blk("heading_5", txt("Five")), |
| 16 | blk("heading_3", txt("Broken\nheading"))), |
| 17 | page("toggle-heading", with(Block{Type: "heading_2", Known: true, |
| 18 | Toggleable: true, Text: []Run{txt("Open me")}}, |
| 19 | para(txt("Inside.")))), |
| 20 | page("bullets", blk("bulleted_list_item", txt("One")), |
| 21 | with(blk("bulleted_list_item", txt("Two")), |
| 22 | blk("bulleted_list_item", txt("Two a")), |
| 23 | with(blk("bulleted_list_item", txt("Two b")), |
| 24 | todo(true, txt("Deep task")))), |
| 25 | blk("bulleted_list_item", txt("Three"))), |
| 26 | page("item-continuation", with(blk("bulleted_list_item", |
| 27 | txt("An item")), para(txt("its second line")))), |
| 28 | page("numbered-split", blk("numbered_list_item", txt("Step one")), |
| 29 | with(blk("numbered_list_item", txt("Step two")), |
| 30 | codeOf("go", "fmt.Println(2)")), |
| 31 | blk("numbered_list_item", txt("Step three"))), |
| 32 | page("todos", todo(false, txt("Open")), todo(true, txt("Done"))), |
| 33 | page("toggle", with(blk("toggle", txt("A toggle")), |
| 34 | para(txt("Inside the toggle.")))), |
| 35 | page("quote", with(blk("quote", txt("A quote\nover two lines")), |
| 36 | para(txt("Its text child.")), |
| 37 | blk("bulleted_list_item", txt("a bullet")), |
| 38 | blk("numbered_list_item", txt("first")), |
| 39 | blk("numbered_list_item", txt("second")), |
| 40 | todo(true, txt("a task")), |
| 41 | Block{Type: "divider", Known: true})), |
| 42 | page("callout", with(Block{Type: "callout", Known: true, |
| 43 | Emoji: "💡", Color: "gray_background", |
| 44 | Text: []Run{txt("Remember this.")}}, para(txt("Its child.")))), |
| 45 | page("callout-custom-icon", Block{Type: "callout", Known: true, |
| 46 | IconType: "custom_emoji", Text: []Run{txt("A custom icon.")}}), |
| 47 | page("code", codeOf("Go", "package main\n\nfunc main() {}"), |
| 48 | codeOf("plain text", "no language"), |
| 49 | with(codeOf("JavaScript", "let a = 1\n```inner"))), |
| 50 | page("code-caption", Block{Type: "code", Known: true, |
| 51 | Language: "python", Text: []Run{txt("print(1)")}, |
| 52 | Caption: []Run{txt("A caption")}}), |
| 53 | page("code-both-fences", codeOf("", "```\n~~~\nboth")), |
| 54 | page("divider", para(txt("Above.")), Block{Type: "divider", |
| 55 | Known: true}, para(txt("Below."))), |
| 56 | page("equation", Block{Type: "equation", Known: true, |
| 57 | Expression: `e^{i\pi} + 1 = 0`}), |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func containerFixtures() []fixture { |
| 62 | return []fixture{ |
| 63 | page("table", tableOf(true, []string{"Name", "Role"}, |
| 64 | []string{"Ana", "Lead|Ops"}, []string{"Bo", "Two\nlines"})), |
| 65 | page("table-plain", tableOf(false, []string{"a", "b", "c"}, |
| 66 | []string{"d"})), |
| 67 | page("columns", with(Block{Type: "column_list", Known: true}, |
| 68 | with(Block{Type: "column", Known: true}, para(txt("Left."))), |
| 69 | with(Block{Type: "column", Known: true}, para(txt("Right."))))), |
| 70 | // COL11 (columns and icons spec §6.2): one column, five, a list |
| 71 | // inside a column, a typed fence line, and an empty column. |
| 72 | page("columns-one", columnList(para(txt("Alone.")))), |
| 73 | page("columns-five", columnList(para(txt("A")), para(txt("B")), |
| 74 | para(txt("C")), para(txt("D")), para(txt("E")))), |
| 75 | page("columns-nested", columnList(with(Block{Type: "column_list", |
| 76 | Known: true}, with(Block{Type: "column", Known: true}, |
| 77 | para(txt("In."))), with(Block{Type: "column", Known: true}, |
| 78 | para(txt("Side.")))), para(txt("Right.")))), |
| 79 | page("columns-fence-text", columnList(para(txt(":::")), |
| 80 | para(txt(":::: columns")))), |
| 81 | page("columns-empty", with(Block{Type: "column_list", Known: true}, |
| 82 | Block{Type: "column", Known: true}, |
| 83 | with(Block{Type: "column", Known: true}, para(txt("B."))))), |
| 84 | // Widths that differ are counted; even ones, given or not, are |
| 85 | // not (columns and icons spec §6.2). |
| 86 | page("columns-widths", with(Block{Type: "column_list", Known: true}, |
| 87 | with(Block{Type: "column", Known: true, WidthRatio: 0.25}, |
| 88 | para(txt("Narrow."))), |
| 89 | with(Block{Type: "column", Known: true, WidthRatio: 0.75}, |
| 90 | para(txt("Wide."))))), |
| 91 | page("columns-even", with(Block{Type: "column_list", Known: true}, |
| 92 | with(Block{Type: "column", Known: true, WidthRatio: 0.5}, |
| 93 | para(txt("Half."))), |
| 94 | with(Block{Type: "column", Known: true}, para(txt("Half too."))))), |
| 95 | // Equal ratios that do not sum to 1 are even (Fable on phase 4, |
| 96 | // L5). |
| 97 | page("columns-equal-ones", with(Block{Type: "column_list", |
| 98 | Known: true}, |
| 99 | with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| 100 | para(txt("One."))), |
| 101 | with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| 102 | para(txt("Two."))))), |
| 103 | page("tabs", with(blk("tab", txt("First tab")), para(txt("In it.")))), |
| 104 | page("synced", with(Block{Type: "synced_block", Known: true}, |
| 105 | para(txt("Synced text."))), with(Block{Type: "synced_block", |
| 106 | Known: true, SyncedFrom: "orig"}, para(txt("Mirrored.")))), |
| 107 | page("synced-unshared", Block{Type: "synced_block", Known: true, |
| 108 | SyncedFrom: "gone-original", OriginalUnshared: true}), |
| 109 | page("meeting", with(Block{Type: "meeting_notes", Known: true, |
| 110 | Title: "Standup"}, para(txt("Notes."))), |
| 111 | named(Block{Type: "meeting_notes", Known: true, |
| 112 | Title: "Empty"}, "meet-2")), |
| 113 | page("dropped", Block{Type: "breadcrumb", Known: true}, |
| 114 | Block{Type: "table_of_contents", Known: true}, |
| 115 | blk("template", txt("A template button"))), |
| 116 | page("unknown", Block{Type: "unsupported", Unsupported: "form"}, |
| 117 | Block{Type: "ai_block", Text: []Run{txt("Something new.")}}, |
| 118 | Block{Type: "paragraph", Text: []Run{txt("Unreadable.")}}), |
| 119 | page("children-pages", named(Block{Type: "child_page", |
| 120 | Known: true, Title: "Child"}, hexID("c1")), |
| 121 | named(Block{Type: "child_page", Known: true, |
| 122 | Title: "Failed child"}, hexID("c2"))). |
| 123 | live(hexID("c1"), "Child (Onboarding)").state(hexID("c2"), "dead"), |
| 124 | page("link-to-page", Block{Type: "link_to_page", Known: true, |
| 125 | LinkTo: &Target{Type: "page", ID: hexID("a1")}}, |
| 126 | Block{Type: "link_to_page", Known: true, |
| 127 | LinkTo: &Target{Type: "page", ID: hexID("a2")}}). |
| 128 | live(hexID("a1"), "Acme"), |
| 129 | page("database", named(Block{Type: "child_database", Known: true, |
| 130 | Title: "Projects"}, "db-1")), |
| 131 | // The look is the runner's: the mapper writes nothing of it |
| 132 | // (columns and icons spec §6.1). |
| 133 | {Name: "page-icon-cover", Page: Page{ID: "page-icon", |
| 134 | Icon: &Look{Type: "emoji", Emoji: "🚀"}, |
| 135 | Cover: &Look{Type: "external", URL: "https://example.com/c.jpg"}, |
| 136 | Blocks: []Block{para(txt("A page with an icon and a cover."))}}}, |
| 137 | {Name: "parent-and-date", Page: Page{ID: "page-day", |
| 138 | Blocks: []Block{para(txt("What happened that day."))}}, |
| 139 | Parent: "Journal", Date: "2024-03-05"}, |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // tableOf is a table with rows of one-run cells. |
| 144 | func tableOf(header bool, rows ...[]string) Block { |
| 145 | table := Block{Type: "table", Known: true, |
| 146 | Table: &Table{ColumnHeader: header}} |
| 147 | for _, row := range rows { |
| 148 | var cells [][]Run |
| 149 | for _, cell := range row { |
| 150 | cells = append(cells, []Run{txt(cell)}) |
| 151 | } |
| 152 | table.Children = append(table.Children, Block{Type: "table_row", |
| 153 | Known: true, Cells: cells}) |
| 154 | } |
| 155 | return table |
| 156 | } |
| 157 | |
| 158 | // mediaFixtures are images, files and links to elsewhere. |
| 159 | func mediaFixtures() []fixture { |
| 160 | refused := "(Image not imported: diagram.png, the file is too large)" |
| 161 | return []fixture{ |
| 162 | {Name: "image-hosted", Page: Page{ID: "page-image", Blocks: []Block{ |
| 163 | named(fileOf("image", "file", hosted1, ""), "img-1"), |
| 164 | named(fileOf("image", "file", hosted1, ""), "img-2"), |
| 165 | named(fileOf("image", "file", hosted1, ""), "img-3")}}, |
| 166 | Images: map[string]string{"img-1": refused, |
| 167 | "img-2": ""}}, |
| 168 | page("image-external", Block{Type: "image", Known: true, |
| 169 | File: &File{Type: "external", URL: "https://example.com/a.jpg"}, |
| 170 | Caption: []Run{txt("A photo")}}, |
| 171 | fileOf("image", "external", "https://example.com/b (1).jpg", "")), |
| 172 | page("files", named(fileOf("pdf", "file", hosted2, ""), "pdf-1"), |
| 173 | fileOf("file", "external", "https://example.com/notes.txt", |
| 174 | "notes.txt"), |
| 175 | fileOf("video", "external", "https://example.com/talk.mp4", ""), |
| 176 | named(fileOf("audio", "file_upload", "", "memo.m4a"), "aud-1")), |
| 177 | page("embeds", Block{Type: "embed", Known: true, |
| 178 | URL: "https://example.com/embed", Caption: []Run{txt("An embed")}}, |
| 179 | Block{Type: "bookmark", Known: true, URL: "https://example.com/r"}, |
| 180 | Block{Type: "link_preview", Known: true, |
| 181 | URL: "https://github.com/x/y/pull/1"}, |
| 182 | Block{Type: "embed", Known: true, URL: "javascript:alert(1)"}), |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const ( |
| 187 | hosted1 = "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/" + |
| 188 | "a/diagram.png?X-Amz-Expires=3600" |
| 189 | hosted2 = "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/" + |
| 190 | "b/report%20final.pdf?X-Amz-Expires=3600" |
| 191 | ) |
| 192 | |
| 193 | // columnList is a column list, one column per block. |
| 194 | func columnList(blocks ...Block) Block { |
| 195 | list := Block{Type: "column_list", Known: true} |
| 196 | for _, block := range blocks { |
| 197 | list.Children = append(list.Children, |
| 198 | with(Block{Type: "column", Known: true}, block)) |
| 199 | } |
| 200 | return list |
| 201 | } |
| 202 | |