Skip to content

Add support for the table of contents block type #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableOfContentsUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }

[JsonProperty("table_of_contents")]
public Data TableOfContents { get; set; }

public class Data
{
}

public TableOfContentsUpdateBlock()
{
TableOfContents = new Data();
}
}
}
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Blocks/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)]
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public enum BlockType
[EnumMember(Value = "audio")]
Audio,

[EnumMember(Value = "table_of_contents")]
TableOfContents,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
16 changes: 16 additions & 0 deletions Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableOfContentsBlock : Block
{
public override BlockType Type => BlockType.TableOfContents;

[JsonProperty("table_of_contents")]
public Data TableOfContents { get; set; }

public class Data
{
}
}
}
26 changes: 23 additions & 3 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
new DividerBlock
{
Divider = new DividerBlock.Data()
},
new TableOfContentsBlock
{
TableOfContents = new TableOfContentsBlock.Data()
}
}
}
);

blocks.Results.Should().HaveCount(2);
blocks.Results.Should().HaveCount(3);

// cleanup
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
Expand Down Expand Up @@ -133,12 +137,16 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
new DividerBlock
{
Divider = new DividerBlock.Data()
}
},
new TableOfContentsBlock
{
TableOfContents = new TableOfContentsBlock.Data()
},
}
}
);

blocks.Results.Should().HaveCount(1);
blocks.Results.Should().HaveCount(2);

// cleanup
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
Expand Down Expand Up @@ -291,6 +299,18 @@ private static IEnumerable<object[]> BlockData()
.Audio.Should().BeOfType<ExternalFile>().Subject
.External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3");
})
},
new object[]
{
new TableOfContentsBlock {
TableOfContents = new TableOfContentsBlock.Data()
},
new TableOfContentsUpdateBlock(),
new Action<Block>((block) =>
{
Assert.NotNull(block);
Assert.IsType<TableOfContentsBlock>(block);
})
}
};
}
Expand Down