Skip to content

Commit 07d09c4

Browse files
Merge pull request #274 from notion-dotnet/226-add-table-block-support
Add support for Table and TableRow block ✨
2 parents 5de4799 + f739b99 commit 07d09c4

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock
7+
{
8+
[JsonProperty("table_row")]
9+
public Info TableRow { get; set; }
10+
11+
public class Info
12+
{
13+
[JsonProperty("cells")]
14+
public IEnumerable<IEnumerable<RichTextTextInput>> Cells { get; set; }
15+
}
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableUpdateBlock : UpdateBlock, IUpdateBlock
6+
{
7+
[JsonProperty("table")]
8+
public Info Table { get; set; }
9+
10+
public class Info
11+
{
12+
[JsonProperty("has_column_header")]
13+
public bool HasColumnHeader { get; set; }
14+
15+
[JsonProperty("has_row_header")]
16+
public bool HasRowHeader { get; set; }
17+
}
18+
}
19+
}

Src/Notion.Client/Models/Blocks/BlockType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public enum BlockType
9191
[EnumMember(Value = "synced_block")]
9292
SyncedBlock,
9393

94+
[EnumMember(Value = "table")]
95+
Table,
96+
97+
[EnumMember(Value = "table_row")]
98+
TableRow,
99+
94100
[EnumMember(Value = "unsupported")]
95101
Unsupported
96102
}

Src/Notion.Client/Models/Blocks/IBlock.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace Notion.Client
2828
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
2929
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
3030
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
31+
[JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)]
32+
[JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)]
3133
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
3234
[JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)]
3335
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock
6+
{
7+
public override BlockType Type => BlockType.Table;
8+
9+
[JsonProperty("table")]
10+
public TableInfo Table { get; set; }
11+
12+
public class TableInfo
13+
{
14+
[JsonProperty("table_width")]
15+
public int TableWidth { get; set; }
16+
17+
[JsonProperty("has_column_header")]
18+
public bool HasColumnHeader { get; set; }
19+
20+
[JsonProperty("has_row_header")]
21+
public bool HasRowHeader { get; set; }
22+
23+
[JsonProperty("children")]
24+
public TableRowBlock Children { get; set; }
25+
}
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock
7+
{
8+
public override BlockType Type => BlockType.TableRow;
9+
10+
[JsonProperty("table_row")]
11+
public Info TableRow { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("cells")]
16+
public IEnumerable<IEnumerable<RichTextText>> Cells { get; set; }
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)