Skip to content

Commit f770869

Browse files
fix: correctly handle indentation of nested child blocks
1 parent e74c838 commit f770869

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/BlockRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class BlockRenderer {
6868
private readonly richText: RichTextRenderer
6969
) {}
7070

71-
async renderBlockLine(block: Block, assets: AssetWriter): Promise<string> {
71+
async renderBlock(block: Block, assets: AssetWriter): Promise<string> {
7272
switch (block.type) {
7373
case "paragraph":
7474
return this.richText.renderMarkdown(block.paragraph.text);

src/RecursiveBodyRenderer.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class RecursiveBodyRenderer {
3434
}
3535

3636
const heading = `# ${props.values["title"]}\n\n`;
37-
37+
3838
return heading + body;
3939
}
4040

@@ -43,8 +43,8 @@ export class RecursiveBodyRenderer {
4343
indent: string,
4444
assets: AssetWriter
4545
): Promise<string> {
46-
const parentLine =
47-
indent + (await this.blockRenderer.renderBlockLine(block, assets));
46+
const parentBlock = await this.blockRenderer.renderBlock(block, assets);
47+
const parentLines = this.indent(parentBlock, indent);
4848

4949
// due to the way the Notion API is built, we need to recurisvely retrieve child
5050
// blocks, see https://developers.notion.com/reference/retrieve-a-block
@@ -59,6 +59,13 @@ export class RecursiveBodyRenderer {
5959
);
6060
const childLines = await Promise.all(renderChilds);
6161

62-
return [parentLine, ...childLines].join("\n\n");
62+
return [parentLines, ...childLines].join("\n\n");
63+
}
64+
65+
private indent(content: string, indent: string) {
66+
return content
67+
.split("\n")
68+
.map((x) => indent + x)
69+
.join("\n");
6370
}
6471
}

0 commit comments

Comments
 (0)