Skip to content

Commit c952f9d

Browse files
committed
Support columns
1 parent 6f72442 commit c952f9d

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dist/**/*"
99
],
1010
"scripts": {
11-
"build": "tsc",
11+
"build": "cp ./src/css/*.css ./dist && tsc",
1212
"clean": "rm -rf ./dist/",
1313
"semantic-release": "semantic-release",
1414
"typecheck": "tsc --noEmit",

src/CustomTranformers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ async function notionColumnListToMarkdown(
2828
notionClient: Client,
2929
block: ListBlockChildrenResponseResult
3030
): Promise<string> {
31+
// Enhance: The @notionhq/client, which uses the official API, cannot yet get at column formatting information (column_ratio)
32+
// However https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/block.tsx#L528 can get it.
33+
3134
const { id, has_children } = block as any; // "any" because the notion api type system is complex with a union that don't know how to help TS to cope with
3235

3336
if (!has_children) return "";
@@ -40,14 +43,15 @@ async function notionColumnListToMarkdown(
4043

4144
const columns: string[] = await Promise.all(column_list_promise);
4245

43-
return `<div class='column_list'>${columns.join("\n\n")}</div>`;
46+
return `<div class='notion-row'>\n${columns.join("\n\n")}\n</div>`;
4447
}
4548

4649
async function notionColumnToMarkdown(
4750
notionToMarkdown: NotionToMarkdown,
4851
notionClient: Client,
4952
block: ListBlockChildrenResponseResult
5053
): Promise<string> {
54+
console.log(JSON.stringify(block));
5155
const { id, has_children } = block as any; // "any" because the notion api type system is complex with a union that don't know how to help TS to cope with
5256

5357
if (!has_children) return "";
@@ -60,7 +64,11 @@ async function notionColumnToMarkdown(
6064

6165
const childrenStrings: string[] = await Promise.all(childrenPromise);
6266

63-
return `<div class='column'>${childrenStrings.join("\n\n")}</div>`;
67+
// note: it would look better in the markup with \n, but that
68+
// causes notion-to-md to give us ":::A" instead of \n for some reason.
69+
return `<div class='notion-column'>\n\n${childrenStrings.join(
70+
"\n\n"
71+
)}\n\n</div>`;
6472
}
6573

6674
async function getBlockChildren(

src/css/notion-styles.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* some things copied from https://github1s.com/NotionX/react-notion-x/blob/master/packages/react-notion-x/src/styles.css#L934 */
2+
/* note, I haven't figure out how a Docusaurus app can actually include this, yet */
3+
4+
.notion-column {
5+
display: flex;
6+
flex-direction: column;
7+
padding-top: 12px;
8+
padding-bottom: 12px;
9+
}
10+
11+
.notion-column > *:first-child {
12+
margin-top: 0;
13+
margin-left: 0;
14+
margin-right: 0;
15+
}
16+
17+
.notion-column > *:last-child {
18+
margin-left: 0;
19+
margin-right: 0;
20+
margin-bottom: 0;
21+
}
22+
23+
.notion-row {
24+
display: grid;
25+
grid-auto-flow: column;
26+
/* at the moment, notion-pull doesn't give us column widths or ratios. So we
27+
could let css layout decide the widths. Instead at the moment we're saying
28+
let's just have each column be equal. This is easier for the author using
29+
Notion to remember than having to guess at what the layout will be. */
30+
grid-auto-columns: 1fr;
31+
overflow: hidden;
32+
width: 100%;
33+
max-width: 100%;
34+
gap: 30px;
35+
}
36+
37+
@media (max-width: 640px) {
38+
.notion-row {
39+
flex-direction: column;
40+
}
41+
42+
.notion-row .notion-column {
43+
width: 100% !important;
44+
}
45+
46+
.notion-row .notion-spacer {
47+
display: none;
48+
}
49+
}

0 commit comments

Comments
 (0)